%fopen() Function

The %fopen() function opens the host OS file designated by str and associates a stream with it.

Syntax

stream = (char*)%fopen(str, type)

Parameter(s)

str

Specifies the file to open.

type

Character string having one of these values:

r

Opens for reading only.

r+

Opens for update.

w

Truncates or creates for writing only.

w+

Truncates or creates for update.

a

Append. Opens for writing at the end of file or creates for writing.

a+

Append. Opens for writing at the end of file or creates for update.

Description

The stream is returned as a pointer to a character or 0 if an error occurred. system(0) contains the error number.

NOTE

In D3, files are closed automatically when the FlashBASIC programs terminate. However, it is strongly recommended that you close all descriptors explicitly.

Example(s)

stream=(char*)%fopen(’fname’,"w+")

if stream=0 then

crt ’Cannot open stream. errno=’:system(0)

end

See Also

%fclose() Function

%fdopen() Function

%fgetc() Function

%fgets() Function

%fprintf() Function

%fputc() Function

%freopen() Function

FlashBASIC C Functions Overview

cfunction Statement