_eof

测试文件尾 (EOF)。

int _eof( 
   int fd 
);

参数

  • fd
    引用打开文件的描述符。

返回值

_eof 返回 1; 如果当前位置的文件结尾,或者 0,则不是。 返回值 – 1 表示错误;在这种情况下,参数无效调用处理程序,如 参数验证所述。 如果执行允许继续, errno 设置为 EBADF,指示一个文件无效描述符。

备注

_eof 函数确定文件的末尾与 fd 是否已到达。

要求

功能

必需的头

可选标头

_eof

io.h

errno.h

有关更多兼容性信息,请参见中介绍的 兼容性

示例

// 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 );
}

输入:crt_eof.txt

This file contains some text.

2hwz7wst.collapse_all(zh-cn,VS.110).gifOutput

Number of bytes read = 29

.NET Framework 等效项

不适用。若要调用标准 C 函数,请使用 PInvoke。有关更多信息,请参见 平台调用示例

请参见

参考

错误处理(crt)

底层I/O

clearerr

feof

ferror

perror, _wperror