_eof

ファイル (EOF) の終端のかをテストします。

int _eof( 
   int fd 
);

パラメーター

  • fd
    開いているファイルを参照するファイル記述子。

戻り値

_eof がない場合は現在位置がファイルの終端に達するとしない場合は 10 を返します。1 を返しエラーを示しています ; この場合無効なパラメーター ハンドラーが パラメーターの検証 に説明されているように開始されます。実行の継続が許可 errno は EBADF に無効なファイル記述子を示すを設定します。

解説

_eof の関数は fd に関連付けられたファイルの終端に到達したかどうかを判定します。

必要条件

Function

必須ヘッダー

オプション ヘッダー

_eof

<io.h>

<errno.h>

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

使用例

// 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(ja-jp,VS.110).gif出力

Number of bytes read = 29

同等の .NET Framework 関数

該当なし標準 C 関数を呼び出すには、PInvoke を使用します。詳細については、「プラットフォーム呼び出しの例」を参照してください。

参照

関連項目

エラー処理 (CRT)

下位入出力

clearerr

feof

ferror

perror、_wperror