Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdio.h>
    FILE *fopen( const char *filename, const char *mode );
    FILE *_wfopen( const wchar_t *filename,
                   const wchar_t *mode );

Description:
    The fopen function opens the file whose name is the string pointed to by
    filename, and associates a stream with it.  The argument mode points to
    a string beginning with one of the following sequences:

    Mode     Meaning

"r"
    open file for reading

"w"
    create file for writing, or truncate to zero length

"a"
    append:  open file or create for writing at end-of-file

"r+"
    open file for update (reading and/or writing)

"w+"
    create file for update, or truncate to zero length

"a+"
    append:  open file or create for update, writing at end-of-file

    In addition to the above characters, you can also include one of the
    following characters in mode to specify the translation mode for newline
    characters:

    t
        The letter "t" may be added to any of the above sequences in the
        second or later position to indicate that the file is (or must be) a
        text file.  It also overrides the global translation mode flag if
        you link your program with BINMODE.OBJ.  The global translation mode
        flag default is "text" unless you explicitly link your program with
        BINMODE.OBJ.

        When neither "t" nor "b" is specified, the value of the global
        variable  _fmode establishes whether the file is to treated as a
        binary or a text file.  Unless this value is changed by the program
        or you have linked your program with BINMODE.OBJ, the default will
        be text mode.

    b
        The letter "b" may be added to any of the above sequences in the
        second or later position to indicate that the file is (or must be) a
        binary file (an ANSI requirement for portability to systems that
        make a distinction between text and binary files).

    You can also include one of the following characters to enable or
    disable the "commit" flag for the associated file.

    c
        The letter "c" may be added to any of the above sequences in the
        second or later position to indicate that any output is committed by
        the operating system whenever a flush (  fflush or  flushall) is
        done.

        This option is not supported under Netware.

    n
        The letter "n" may be added to any of the above sequences in the
        second or later position to indicate that the operating system need
        not commit any output whenever a flush is done.  It also overrides
        the global commit flag if you link your program with COMMODE.OBJ.
         The global commit flag default is "no-commit" unless you explicitly
        link your program with COMMODE.OBJ.

        This option is not supported under Netware.

    The "t", "c", and "n" mode options are extensions for fopen and  _fdopen
    and should not be used where ANSI portability is desired.

    Opening a file with read mode (r as the first character in the mode
    argument) fails if the file does not exist or it cannot be read.
     Opening a file with append mode (a as the first character in the mode
    argument) causes all subsequent writes to the file to be forced to the
    current end-of-file, regardless of previous calls to the  fseek
    function.  When a file is opened with update mode (+ as the second or
    later character of the mode argument), both input and output may be
    performed on the associated stream.

    When a stream is opened in update mode, both reading and writing may be
    performed.  However, writing may not be followed by reading without an
    intervening call to the  fflush function or to a file positioning
    function ( fseek,  fsetpos,  rewind).  Similarly, reading may not be
    followed by writing without an intervening call to a file positioning
    function, unless the read resulted in end-of-file.

    The _wfopen function is identical to fopen except that it accepts
    wide-character string arguments for filename and mode.

Returns:
    The fopen function returns a pointer to the object controlling the
    stream.  This pointer must be passed as a parameter to subsequent
    functions for performing operations on the file.  If the open operation
    fails, fopen returns NULL.  When an error has occurred,  errno contains
    a value indicating the type of error that has been detected.

Example:
    #include <stdio.h>

    void main()
      {
        FILE *fp;

        fp = fopen( "file", "r" );
        if( fp != NULL ) {
          /* rest of code goes here */
          fclose( fp );
        }
      }

Classification:
    ANSI, ('t', 'c', 'n' are Watcom extensions)

Systems:
     fopen - All, Netware

    _wfopen - All

See Also:
    fclose, fcloseall, fdopen, freopen, _fsopen

See Also: fclose fcloseall

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