Export (0) Print
Expand All
div
eof
Expand Minimize
1 out of 1 rated this helpful - Rate this topic

_eof 

Tests for end of file (EOF).


int _eof( 
   int fd 
);

Parameters

fd

File descriptor referring to the open file.

_eof returns 1 if the current position is end of file, or 0 if it is not. A return value of –1 indicates an error; in this case, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, errno is set to EBADF, which indicates an invalid file descriptor.

The _eof function determines whether the end of the file associated with fd has been reached.

Function Required header Optional header Compatibility

_eof

<io.h>

<errno.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

// crt_eof.c
// This program reads data from a file
// ten bytes at a time until the end of the
// file is reached or an error is encountered.
//
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <share.h>

int main( void )
{
   int  fh, count, total = 0;
   char buf[10];
   if( _sopen_s( &fh, "crt_eof.txt", _O_RDONLY, _SH_DENYNO, 0 ) )
   {
        perror( "Open failed");
        exit( 1 );
   }
   // Cycle until end of file reached: 
   while( !_eof( fh ) )
   {
      // Attempt to read in 10 bytes: 
      if( (count = _read( fh, buf, 10 )) == -1 )
      {
         perror( "Read error" );
         break;
      }
      // Total actual bytes read 
      total += count;
   }
   printf( "Number of bytes read = %d\n", total );
   _close( fh );
}
This file contains some text.

Output

Number of bytes read = 29

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.