The feof routine 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.
int feof( FILE * stream )
Returns a nonzero value after the first read operation that attempts to read past the end of the file. It returns 0 if the current position is not end of file. There is no error return.
//The following example uses feof to indicate when it reaches the end of your current C file. It also checks for errors with ferror.
int count, total = 0;
// open your current using C file for read
stream = fopen( __FILE__, "r" );
if(stream == NULL )
printf( "The current C file was not opened\n" );
// Cycle until end of file reached:
while( !feof( stream ) )
// Attempt to read in 10 bytes:
count = fread( buffer, sizeof( char ), 100, stream );
if( ferror( stream ) )
// Total up actual bytes read
total += count;
printf( "Number of bytes read = %d\n", total );
fclose( stream );