Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>fopen() open a file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fopen()                 Open a File

 #include   <stdio.h>

 FILE       *fopen(pathname,type);
 const char *pathname;                   Path name of file
 const char *type;                       Type of access permitted

    fopen() opens a file identified by 'pathname'.  'type' is a character
    string that specifies the type of access requested for the file:

        "r"     Read access; the file must already exist.

        "w"     Write access.  Creates a new file for writing or open an
                existing file for writing.  If the file already exists,
                its contents will be destroyed, so use with caution.

        "a"     Append.  Opens a file for writing at the end-of-file or
                creates a file for writing if the file doesn't exist.
                Existing data cannot be overwritten in this mode.

        "r+"    Update. Opens an existing file for reading and writing;
                the file must exist.

        "w+"    Read and write access.  Opens an empty file for reading
                and writing.  If the file exists, its contents will be
                destroyed, so use with caution.

        "a+"    Read and append.  Opens a file for reading and appending.
                If the file doesn't exist, it is created.  All write
                operations take place at the end of the file; existing
                data cannot be overwritten.

    To specify translation mode for new lines, append either of the
    following characters to 'type':

        t       text, or translated mode: CR-LF pairs are translated into
                LF on input; LF is translated to CR-LF on output.

        b       binary, or untranslated mode; translation of CR-LF to LF
                and LF to CR-LF is suppressed.

    If 't' or 'b' is not specified, the default mode variable '_fmode'
    defines the translation mode.  '_fmode' can be set to O_BINARY,
    binary mode, or O_TEXT, text mode.  These constants are defined in
    <fcntl.h>.

    Returns:    A pointer to the open file.  NULL is returned on error.

      Notes:    Both reading and writing are allowed when using "r+",
                "w+" or "a+".  However, you must have an intervening
                fseek, fsetpos, or rewind operation when switching
                between reading and writing (or vice versa).

 Portability:   The translation mode 't' is a Microsoft extension to the
                ANSI standard, and should not be used if ANSI portability
                is required.
   -------------------------------- Example ---------------------------------

    The following statements open and close a file.

           #include <stdio.h>

           FILE *in;

           main()
           {
               if ((in = fopen("new.dat","w+")) != NULL) {
                   .
                   .
                   .
                   fclose(in);
               }
           }



See Also: fdopen() freopen() open() fclose() fcloseall()

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