feof

Tests the end-of-file indicator for a stream (function or macro)

Local Servers:nonblocking
Remote Servers:nonblocking
Classification:ANSI
Platform:NLM
Service:Stream I/O

Syntax

  #include <stdio.h>  
   
  int feof  ( 
     FILE   *fp);
  

Parameters

fp
(IN) Points to the file to be tested.

Return Values

feof returns nonzero if the EOF indicator is set for fp.

Remarks

The feof function or macro tests the end-of-file indicator for the file pointed to by fp. Because this indicator is set when an input operation attempts to read past the end of the file, feof detects the end of the file only after an attempt is made to read beyond the end of the file. Thus, if a file contains 10 lines, feof does not detect the end of the file after the tenth line is read; it detects the end of the file once the program attempts to read more data.

See Also

clearerr, ferror, fopen, freopen, read

feof Example

  #include <stdio.h> 
    
  main ()  
  {  
     FILE *fp;  
     char buffer[100];  
     fgets (buffer, sizeof (buffer), fp);  
     while (! feof (fp) )  
     {  
        process_record (buffer);  
        fgets (buffer, sizeof (buffer), fp);  
     }  
  }