Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>fopen</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
fopen

Usage

   #include <stdio.h>
   FILE *fopen(char *name,char *mode);

   ANSI

Description

   fopen opens a file. name gives the filename to be opened. mode is a
   character string indicating how the file is to be opened. Possible values
   for mode are:

   "r"              for reading

   "w"              for writing (truncates any existing file with the same
                    name)

   "a"              for appending (if file exists then open for writing at end
                    of file, else create the file)

   "r+"             for reading and writing


   "w+"             for reading and writing (if file exists then truncate it,
                    else create it)

   "a+"             for reading and writing (if file exists, position at end
                    of file, else create it)

   In addition, a b may be appended to the mode string to indicate that the
   file is to be opened in binary mode (the default is text mode). If a file
   is opened for reading and writing, only reads or only writes can be done
   at any one time. To switch from reading to writing, or vice versa, an
   fseek must be performed on the stream, unless during input an EOF was
   read.

Example 

   #include <stdio.h>
   #include <stdlib.h>

   int main()
   {
       FILE *fp;
       fp = fopen("file.dat","r");
       printf("Open text file\n");
       if(fp) fclose(fp);
       fp = fopen("file.dat","a+");
       printf("ASCII update file\n");
       if(fp) fclose(fp);
       return EXIT_SUCCESS;
   }

Return Value

   fopen returns a FILE pointer to an open file. A NULL pointer value
   indicates an error.

See Also

   fclose, freopen, open



See Also: fclose freopen open

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