### __eof -- Determine End of File

Format

>     #include <io.h>
>     int __eof (int handle);

Language Level: Extension
__eof determines whether the file pointer has reached the end-of-file for the file associated with handle. You cannot use __eof on a nonseekable file; it will fail.

Return Value
__eof returns the value 1 if the current position is the end of the file or 0 if it is not. A return value of -1 shows an error, and the system sets errno to the following values:

Value | Meaning
EBADF | File handle is not valid.
EOS2ERR | The call to the operating system was not successful.

Example
This example creates the file sample.dat and then checks if the file pointer is at the end of that file using the __eof function.

    #include <sys\stat.h>
    #include <io.h>
    #include <stdio.h>
    #include <stdlib.h>

    int main(void)
    {
       int fh,returnValue;

       fh = creat("sample.dat", S_IREAD|S_IWRITE);
       if (-1 == fh) {
          perror("Error creating sample.dat");
          return EXIT_FAILURE;
       }
       if (-1 == (returnValue = __eof(fh))) {
          perror("eof function error");
          return EXIT_FAILURE;
       }
       if (1 == returnValue)
          printf("File pointer is at end-of-file position.\n");
       else
          printf("File pointer is not at end-of-file position.\n");
       close(fh);
       return 0;

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

          File pointer is at end-of-file position.
       ************************************************************/
    }

_chsize -- Alter Length of File
creat -- Create New File
_filelength -- Determine File Length
<sopen> -- Open Shared File
open -- Open File
<io.h>