index

Varkon MBS Programmers manual


open - Procedure

Description

Used to establish connection with an existing file or to create a new file or pipe to another program.

Syntax

  open(f, mode, name);

  file f;
  string mode;
  string name;

Principal parameters

f - The name of a filevariable to be used for successive operations
mode - Type of operations to be allowed on the opened file or pipe
   R = Read from file
   W = Write to file (if file exists it is overwritten otherwise it is created)
   A = Append to file (if no file exists it is created)
   U = Update (read, write and seek)
   RP = Read from pipe
   WP = Write to pipe
name - Name and path of file to open or command to create the pipe

Optional parameters

None.

Examples

  FILE f;

  open(f, "r" , "/usr/mydir/job.dat"); ! Opens a file named job.dat in /usr/mydir for reading only.

  open(f, "w", "new.dat"); ! Creates a new file named new.dat in current directory.

  open(f, "rp", "cd /usr/mydir;ls"); ! Creates a read-pipe to the output of the ls-program.

Comments

Mode codes may be upper or lower case.

open() automatically resets the current filepointer position within the file to zero.

An attempt to open a file more than once without first closing it is treated as an error. It is also important to close the file before accessing it from other programs than Varkon.

The iostat() function can be used to detect errors.

All files opened by the open() procedure are automatically closed when you exit Varkon.

See also

close()


SourceForge.net Logo

Varkon 1.19D svn # 120M