Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Telix/SALT v3.15 & RS-232, Hayes - <b>fopen</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  FOPEN

  .  Summary

  fopen(str <name>, str <mode>);

  .  Description

  The fopen function is used to open a disk file for reading and/or
  writing. The file to be opened is given by <name>. <mode> is a
  string indicating for what use the file should be opened. Legal val-
  ues for mode are:

       "r"       Opens for reading
       "w"       Opens for writing (truncates any existing file with
                 the same name)
       "a"       Opens for appending (writing at the end of the file).
                 Creates the file if it doesn't exist.
       "r+"      Opens for reading and writing. Initial position at
                 the beginning of the file (the file must already ex-
                 ist).
       "w+"      Opens for reading and writing. If the file exists its
                 contents are destroyed.
       "a+"      Opens for reading and appending. Creates the file if
                 it doesn't exist.

  If a file is opened for both reading and writing (when "r+", "w+",
  or "a+" are used as the mode), an fseek operation is necessary be-
  fore switching from one to the other.

  .  Return Value

  The fopen function returns a 'handle' which is an integer number by
  which this file is to be referred to until it is finally closed. A
  value of 0 is returned if the file can not be opened (because it
  doesn't exist, because a disk error occurred, or because there are
  no more file handles available). Only up to 8 files may be opened at
  a time. It is therefore very important to close open files if they
  are no longer needed and when a script is done, or else all avail-
  able file handles will become used up.

  .  Example

  int f;
  f = fopen("data.txt", "r");    // open the file for reading
  if (f == 0)
   prints("Error opening file!");

See Also: fclose

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson