_eof

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

구문

int _eof(
   int fd
);

매개 변수

fd
열려 있는 파일을 참조하는 파일 설명자입니다.

반환 값

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

설명

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

기본적으로 이 함수의 전역 상태는 애플리케이션으로 범위가 지정됩니다. 이 동작을 변경하려면 CRT의 전역 상태를 참조하세요.

요구 사항

함수 필수 헤더 선택적 헤더
_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.

출력

Number of bytes read = 29

참고 항목

오류 처리
하위 수준 I/O
clearerr
feof
ferror
perror, _wperror