clearerr


clearerr

Clears the file error and EOF flags

 #include <stdio.h> void clearerr(FILE *fp); 

The clearerr( ) function is useful in handling errors in file I/O routines. It clears the end-of-file (EOF) and error flags associated with a specified FILE pointer.

Example

 FILE *fp; int c; if ((fp = fopen("infile.dat", "r")) == NULL)   fprintf(stderr, "Couldn't open input file.\n"); else {   c = fgetc(fp);   // fgetc( ) returns a character on success;   if (c == EOF)    // EOF means either an error or end-of-file.   {     if (feof(fp))       fprintf(stderr, "End of input file reached.\n");     else if (ferror(fp))       fprintf(stderr, "Error on reading from input file.\n");     clearerr(fp);    // Same function clears both conditions.   }   else   { /* ... */ }      // Process the character that we read. } 

See Also

feof( ), ferror( ), rewind( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net