In C programming the <stdio.h> clearerr function clears the end-of-file and error indicators for the stream.The declaration of the function is given below.
|void clearerr(FILE *stream);|
stream -The pointer to the file whose EOF and error indicator is to be cleared.
A code example is given below.
int val , count ;
if (fp != NULL)
while ( true) //read text.bin file
val=fgetc(fp); //read character from the file
if( feof(fp) )
fprintf(stderr , “\nEnd of file has reached”);
else if ( ferror(fp) )
fprintf( stderr, “\nAn error has occurred”);
printf(“%c”, val); //print the character or process the character
printf(“File cannot be opened”);
fclose( fp )
The above program read character from the file and checks if EOF has reached or an error has occurred while reading.