feof prog..........

<자료 출처, msdn : 번역 지못미..>

feof
Tests for end-of-file on a stream.
스트림의 end-of-file에 대해 테스트한다.

int feof( FILE *stream );

Function Required Header Compatibility
함수의 요구된 헤더 호환성
feof <stdio.h> ANSI, Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.
추가적인 호완성 정보에 대해서는 소개에 나온 호환성을 봐라

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value
리턴 값

The feof function returns a nonzero value after the first read operation that attempts to read past the end of the file.
feof 함수는 end of the file을 지나서 읽기를 시도하는 첫번째 읽기 동작 후에 0이 아닌 값을 리턴한다.

It returns 0 if the current position is not end of file.
만약 현재 포지션(파일 포인터가 가르키는 곳)이 end of file이 아니라면 0을 리턴한다.
There is no error return.
에러 리턴이 아니다.(0을 리턴한다고 에러는 아니라는 말인듯)

Parameter

stream

Pointer to FILE structure

Remarks

The feof routine (implemented both as a function and as a macro) determines
whether the end of stream has been reached.
When end of file is reached, read operations return an end-of-file indicator
until the stream is closed or until rewind, fsetpos, fseek, or clearerr is called against it.

Example

/* FEOF.C: This program uses feof to indicate when
 * it reaches the end of the file FEOF.C. It also
 * checks for errors with ferror.
 */

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

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

   if( (stream = fopen( "feof.c", "r" )) == NULL )
      exit( 1 );

   /* Cycle until end of file reached: */
   while( !feof( stream ) )
   {
      /* Attempt to read in 10 bytes: */ 10바이트씩 읽기를 시도한다고 했는데 오타 인듯.. 100바이트씩 읽으면서 ㅡㅡ;
      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 );
}


Output

Number of bytes read = 745


Error Handling Routines |  Stream I/O Routines

See Also   clearerr, _eof, ferror, perror

실제로 몇 번 돌려봤는데, feof로 파일 스트림을 테스트 해보면
eof에 도달했을때 feof함수는 몇번 반복실험에도 16 값만 리턴하였다


리턴값에 의미가 있는줄 알았지만(남은 바이트 읽은 갯수라던지..)
별 의미는 없는듯하다.


트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://bruceKIM.egloos.com/tb/1449652 [도움말]

덧글

덧글 입력 영역