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>eof() test for end of file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 eof()                   Test for End of File

 #include <io.h>

 int        eof(handle);
 int        handle;                      Handle referring to open file

    eof() checks the file associated with 'handle' to find out whether
    end-of-file has been reached.

       Returns:      1   End of file reached
                     0   Current position is not end of file
                    -1   An error occurred.

                    On error, 'errno' is set to:

                        EBADF:        a bad file handle.

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

    The following statements open a file for reading then count the
    number of bytes read until end of file is reached.

           #include <io.h>
           #include <fcntl.h>

           int fhndl, count, totalbytes;
           char buff[1000];

           main()
           {
               fhndl = open("data",O_RDONLY);
               totalbytes = 0;
               while (!eof(fhndl)) {
                   count = read(fhndl, buff, 10);
                   totalbytes += count;
               }
           }



See Also: clearerr() feof() ferror() perror()

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