Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo 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() tests 'stream' for reading or writing errors.  If an error
    has occurred, the stream's error indicator will remain set until a
    call to rewind() or clearerr() is made or until '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