Share via


_eof

파일의 끝(EOF)을 테스트 합니다.

int _eof( 
   int fd 
);

매개 변수

  • fd
    열려 있는 파일을 나타내는 파일 기술자입니다.

반환 값

_eof 는 현재 위치가 파일의 끝인 경우 `을 반환하고 그렇지 않은 경우 0을 반환합니다. 반환 값 -1 은 오류를 나타냅니다. 이 경우 매개 변수 유효성 검사 에 설명된 대로 잘못된 매개 변수 처리기가 호출 됩니다. 실행이 계속해서 허용 되는 경우 errno 는잘못된 파일 설명자를 나타내는 EBADF 로 설정됩니다.

설명

_eof 함수는 fd 와 관련된 파일의 끝에 도달 했는지 여부를 결정합니다.

요구 사항

Function

필수 헤더

선택적 헤더

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

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