next up previous contents index
Next: Read and Write Up: Input and Output Previous: Input and Output

Open and Close

 

  Before a file is accessed it must be opened using the open() statement, and after the last access the file is closed using close(). The open() routine takes two parameters. The first is a string that gives the name of the file to open. The second is a string that specifies the mode of access: "r" for read, "w" for write, and "a" for append. If successful, open() returns a file variable that can be used to access the file as described in the next subsection. If unsuccessful, open() returns 0.

The following example shows how a file is opened for reading.

 

    var f : file;
    . . .

    f := open ("input", "r"); -- open file for reading
The close() procedure takes a file parameter that was obtained from open().



Kay Nettle
Fri Feb 21 21:14:29 CST 1997