feof

测试文件尾在流。

int feof( 
   FILE *stream 
);

参数

  • stream
    为 FILE 结构的指针。

返回值

,如果一次读取操作尝试读取超出文件,结束 feof 函数返回非零值;它否则返回 0。 如果流指针是 NULL,该函数调用的参数无效处理程序,如 参数验证所述。 如果执行允许继续, errno 设置为 EINVAL ,并 feof 返回 0。

请参见 _doserrno、 errno、 _sys_errlist 和 _sys_nerr 有关这些内容的更多信息以及其他情况下,错误代码。

备注

feof 实例 (实现为函数和作为宏) 确定 stream 的结尾是否已通过。 当文件结尾通过时,读取操作返回的文件结尾指示符,直到关闭了流或直到 rewind, fsetpos、 fseek或 clearerr 调用它。

例如,文件,则包含 10 个字节,并且您读取 10 个字节从文件, feof 将返回 0,这是因为,因此,即使文件指针位于文件的末尾,您没有尝试在末尾外读取。 在尝试读取后一个第 11 个字节 feof 将返回一个非零值。

要求

功能

必需的头

feof

stdio.h

有关其他的兼容性信息,请参见中介绍的 兼容性

示例

// crt_feof.c
// This program uses feof to indicate when
// it reaches the end of the file CRT_FEOF.TXT. It also
// checks for errors with ferror.
//

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   int  count, total = 0;
   char buffer[100];
   FILE *stream;

   fopen_s( &stream, "crt_feof.txt", "r" );
   if( stream == NULL )
      exit( 1 );

   // Cycle until end of file reached:
   while( !feof( stream ) )
   {
      // Attempt to read in 100 bytes:
      count = fread( buffer, sizeof( char ), 100, stream );
      if( ferror( stream ) )      {
         perror( "Read error" );
         break;
      }

      // Total up actual bytes read
      total += count;
   }
   printf( "Number of bytes read = %d\n", total );
   fclose( stream );
}

输入:crt_feof.txt

Line one.
Line two.

xssktc6e.collapse_all(zh-cn,VS.110).gifOutput

Number of bytes read = 19

.NET Framework 等效项

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

请参见

参考

错误处理(crt)

流I/O

clearerr

_eof

ferror

perror, _wperror