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.
-
void
clearerr
( FILE *fp
); Clears the error and end-of-file flags.
-
int
fclose
( FILE *fp
); Closes the file.
-
int
feof
( 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.
-
int
ferror
( 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.
-
int
fflush
( FILE *fp
); Causes any unwritten data in the file buffer to be written to the file. Returns
EOF
if an error occurs, or 0 on success.-
int
fgetpos
( FILE *fp
, fpos_t *ppos
); Determines the current file position and copies it to the variable addressed by
ppos
. The typefpos_t
is generally defined aslong
.-
FILE
*fopen
( const char *name
, const char *mode
); Opens the file
name
with 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 appendingt
orb
to the mode string. If ...
Get C Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.