General File Access Functions
The
following functions, macros, and symbolic
constants are declared in the header file
stdio.h
. In the descriptions below,
fp designates the file pointer. Functions
with type int return 0 to indicate success, or a
value other than 0 in case of errors.
-
voidclearerr( FILE *fp); Clears the error and end-of-file flags.
-
intfclose( FILE *fp); Closes the file.
-
intfeof( FILE *fp); Tests whether the end of the file has been reached. Returns a value not equal to 0 if the end-of-file flag is set, or 0 if it is not.
-
intferror( FILE *fp); Tests whether an error occurred during file access. Returns a value not equal to 0 if the error flag is set, or 0 if it is not.
-
intfflush( FILE *fp); Causes any unwritten data in the file buffer to be written to the file. Returns
EOFif an error occurs, or 0 on success.-
intfgetpos( FILE *fp, fpos_t *ppos); Determines the current file position and copies it to the variable addressed by
ppos. The typefpos_tis generally defined aslong.-
FILE*fopen( const char *name, const char *mode); Opens the file
namewith the access modemode. Possible access mode strings are"r"(read),"r+"(read and write),"w"(write),"w+"(write and read),"a"(append), and"a+"(append and read). For modes"r"and"r+", the file must already exist. Modes"w"and"w+"create a new file, or erase the contents of an existing file. Text or binary access mode can be specified by appendingtorbto the mode string. If ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access