Page 158 - C-Language
P. 158

Chapter 22: Files and I/O streams




        Syntax



            •  #include <stdio.h> /* Include this to use any of the following sections */
            •  FILE *fopen(const char *path, const char *mode); /* Open a stream on the file at path with
              the specified mode */
            •  FILE *freopen(const char *path, const char *mode, FILE *stream); /* Re-open an existing
              stream on the file at path with the specified mode */
            •  int fclose(FILE *stream); /* Close an opened stream */
            •  size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); /* Read at most nmemb
              elements of size bytes each from the stream and write them in ptr. Returns the number of
              read elements. */
            •  size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); /* Write nmemb
              elements of size bytes each from ptr to the stream. Returns the number of written elements.
              */
            •  int fseek(FILE *stream, long offset, int whence); /* Set the cursor of the stream to offset,
              relative to the offset told by whence, and returns 0 if it succeeded. */
            •  long ftell(FILE *stream); /* Return the offset of the current cursor position from the beginning
              of the stream. */
            •  void rewind(FILE *stream); /* Set the cursor position to the beginning of the file. */
            •  int fprintf(FILE *fout, const char *fmt, ...); /* Writes printf format string on fout */
            •  FILE *stdin; /* Standard input stream */
            •  FILE *stdout; /* Standard output stream */
            •  FILE *stderr; /* Standard error stream */


        Parameters




          Parameter        Details

          const char       A string describing the opening mode of the file-backed stream. See remarks
          *mode            for possible values.


                           Can be SEEK_SET to set from the beginning of the file, SEEK_END to set from its
          int whence       end, or SEEK_CUR to set relative to the current cursor value. Note: SEEK_END is
                           non-portable.



        Remarks


        Mode strings:



        Mode strings in fopen() and freopen() can be one of those values:





        https://riptutorial.com/                                                                             134
   153   154   155   156   157   158   159   160   161   162   163