Professional Documents
Culture Documents
if(ifp == NULL) {
printf("can't open file\n");
exit or return }
It's common to collapse the call to fopen and the assignment in
with the test:
if((ifp = fopen("input.dat", "r")) == NULL) {
printf("can't open file\n");
exit or return }
int fflush (FILE *fp) Flushes any buffers associated with the file
'fp'.
To check the status of a file, the following functions can be
called:
int feof (FILE *fp) Returns non-zero when an end-of-file is read.
int ferror (FILE *fp) Returns non-zero when an error has
occurred, unless cleared by clearerr.
void clearerr (FILE *fp) Resets the error and end-of-file statuses.
int fileno (FILE *fp) Returns the integer file descriptor associated
with the file (useful for low-level I/O).
fclose(cfptr); } }