ferror
int  ferror (FILE * stream);
stdio.h
  cplusplus.com  

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.

Parameters.

stream
pointer to an open file.

Return Value.
  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.

Example.

/* ferror example: writing error */
#include <stdio.h>
main ()
{
  FILE * pFile;
  pFile=fopen("myfile.txt","r");
  if (pFile==NULL) perror ("Error opening file");
  else {
    fputc ('x',pFile);
    if (ferror (pFile))
      printf ("Error Writing to myfile.txt\n");
    fclose (pFile);
  }
  return 0;
}
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 ferror.
Output.
 Error Writing to myfile.txt

See also.
  feof, clearerr, perror


© The C++ Resources Network, 2000