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 6.0 - <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 'stream' for reading or writing
    errors.  If an error is detected, the stream's error indicator
    remains set until a call to rewind() or clearerr() or until the
    stream is closed.

    Returns:    0, 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() eof() feof() perror() rewind()

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