SourcePoint Intel Help

Table of Contents

fopen

Open a file for input or output.

Syntax

file_handle = fopen(filename,type)

Where:

file_handle

 

specifies a debug variable of type ord4 to receive the file handle.

filename

 

specifies a filename.  See Filenames for details.

type

"r"

opens an existing file for input.

 

"w"

creates a new file, or overwrites an existing one for output.

 

"a"

creates a new file, or appends to an existing one for output.

Discussion

The fopen function opens a file for input or output. It is similar to the "C" language fopen command except that it returns a file handle of type ord4, rather than a file pointer. This file handle is used in subsequent file I/O commands. If the file could not be opened, then 0 is returned.  If a relative path is specified for a filename, then the current working directory (specified with the cwd command) is prepended to the path. If the mode includes "b" after the initial letter, as in "rb" or "w+b", a binary file is indicated. There is no limit to the number of files that may be open.

Use fclose to close a file. If an fopen command is executed within a procedure, then the file handle returned is valid only within that procedure. Open files are closed automatically when the procedure finishes execution. Files opened outside of a procedure have global scope and may be accessed anywhere. Any files left open when SourcePoint terminates are automatically closed.

Example

Command input:

define ord4 file1
file1 = fopen("test.dat", "w")
fputs("this is a test", file1)
fclose(file1)
define nstring buf
file1 = fopen("test.dat", "r")
fgets(buf, file1)

Result:

this is a test

Related Topics: