Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>ferror() test for error on a stream (macro)</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
ferror()                 Test for Error on a Stream (Macro)

 #include   <stdio.h>

 int        ferror(stream);
 FILE       *stream;                     Pointer to file structure

    ferror() is a macro that tests for reading or writing errors in
    'stream'.  If an error has occurred, the stream's error indicator
    remains set until rewind() or clearerr() is called or until the
    stream is closed.

    Returns:    Zero if no error has occurred.  A non-zero value
                indicates an error.


  -------------------------------- Example ---------------------------------

    The following statements open a file and check for reading errors.

         #include <stdio.h>

         FILE *in;
         char str[50], *nstr;

         main()
         {
              if ((in = fopen("text.dat","r+")) != NULL)  {
                 .
                 .
                 nstr = fgets(str,50,in);
                 if (ferror(in)) {
                    printf("read error\n");
                    clearerr(in);
                 }
              }
          }

See Also: clearerr() rewind() eof() feof() perror()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson