contents   index   previous   next



Clib.fopen()

syntax:

Clib.fopen(filename, mode)

where:

filename - a string with a filename to open.

 

mode - how or for what operations the file will be opened.

 

return:

number - a file pointer to the file opened, null in case of failure.

 

description:

This method opens the file specified by filename for file operations specified by mode, returning a file pointer to the file opened. null is returned in case of failure.

 

The parameter filename is a string. It may be any valid file name, excluding wildcard characters.

 

The parameter mode is a string composed of one or more of the following characters. For example, "r" or "rt"

 

r
open file for reading; file must already exist

w
open file for writing; create if doesn't exist; if file exists then truncate to zero length

a
open file for append; create if doesn't exist; set for writing at endoffile

b
binary mode; if b is not specified then open file in text mode (endofline translation)

t
text mode

+
open for update (reading and writing)

 

When a file is successfully opened, its error status is cleared and a buffer is initialized for automatic buffering of reads and writes to the file.

 

see:

Clib.fclose(), Clib.flock()

 

example:

// Open the text file "ReadMe"

// for text mode reading, and

// display each line in the file.

 

var fp = Clib.fopen("ReadMe", "r");

if ( fp == null ) 

   Clib.printf(

        "\aError opening file for reading.\n") 

else 

   while ( null != (line=Clib.fgets(fp)) )

   { 

      Clib.fputs(line, stdout)

   } 

Clib.fclose(fp);

 


Clib.fclose()