int ferror (FILE * stream);
Check for errors.
Tests if a error has occurred in the last reading or writing operation with the given stream, returning a non-zero value in case of error.
If indeed there has been an error the error indicator will not be modified by a call to this function. You should call clearerr or rewind to reset it.
If there were no errors a 0 value is returned.
Otherwise a non-zero value is returned and the error indicator of the stream will remain set.
/* ferror example: writing error */
FILE * pFile;
if (pFile==NULL) perror ("Error opening file");
if (ferror (pFile))
printf ("Error Writing to myfile.txt\n");
This program opens an existing file called myfile.txt in read-only mode
but tries to write a character on it, generating an error that is detected by
Error Writing to myfile.txt
feof, clearerr, perror