共用方式為


_eof

測試檔案結尾(EOF)。

int _eof( 
   int fd 
);

參數

  • fd
    參考開啟檔案的檔案描述項。

傳回值

如果目前位置為檔案結尾,_eof 會傳回 1,否則為 0。 傳回值為 –1 表示錯誤;在這種情況下,無效的參數叫用處理常式,如 參數驗證中所述。 如果執行允許繼續, errno 設定為 EBADF,表示無效的檔案描述項。

備註

_eof 函式來判斷與 fd 相關的檔案結尾是否已到達。

需求

功能

必要的標頭

選擇性標頭

_eof

<io.h>

<errno.h>

如需更多關於相容性的資訊,請參閱入門介紹中的 相容性 (Compatibility)

範例

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

Input: crt_eof.txt

This file contains some text.

Output

Number of bytes read = 29

.NET Framework 對等用法

不適用。若要呼叫標準 C 函式,請使用 PInvoke。如需詳細資訊,請參閱平台叫用範例

請參閱

參考

錯誤處理 (CRT)

低層級 I/O

clearerr

feof

ferror

perror、_wperror