### ferror -- Test for Read/Write Errors

Format

>     #include <stdio.h>
>     int ferror(FILE *stream);

Language Level: ANSI, POSIX, XPG4
ferror tests for an error in reading from or writing to the given stream. If an error occurs, the error indicator for the stream remains set until you close stream, call rewind, or call clearerr.

Return Value
The ferror function returns a nonzero value to indicate an error on the given stream. A return value of 0 means no error has occurred.

Example
This example puts data out to a stream and then checks that a write error has not occurred.

    #include <stdio.h>

    #define  FILENAME "myfile.dat"

    int main(void)
    {
       FILE *stream;
       char *string = "Important information";

       stream = fopen("FILENAME","w");

       fprintf(stream, "%s\n", string);
       if (ferror(stream))
       {
          printf("write error\n");
          clearerr(stream);
          return EXIT_FAILURE;
       }
       else printf("Data written to a file successfully.\n");
       if (fclose(stream))
          perror("fclose error");
       return 0;

       /******************************************************
          The output should be:

          Data written to a file successfully.
       ******************************************************/
    }

clearerr -- Reset Error Indicators
feof -- Test End-of-File Indicator
fopen -- Open Files
perror -- Print Error Message
strerror -- Set Pointer to Runtime Error Message
_strerror -- Set Pointer to System Error String
<stdio.h>