C feof

C feof function is used to determine if the end of the file (stream), specified has been reached or not. This function keeps on searching the end of file (eof) in your file program.

Syntax:
int feof(FILE *stream)

Here is a program showing the use of feof().

Example:
#include<stdio.h> 
int main()
{ 
FILE *filee = NULL; 
char buf[50]; 
filee = fopen("infor.txt","r"); 
if(filee) 
    { 
         while(!feof(filee)) 
         { 
             fgets(buf, sizeof(buf), filee); 
             puts(buf); 
         } 
         fclose(filee); 
   } 
    return 0; 
}
Output:


C feof function returns true in case end of file is reached, otherwise it's return false.

Explanation:
  1. It first tries to open a text file infor.txt as read-only mode.
  2. Then as the file gets opened successfully to read, it initiates the while loop.
  3. The iteration continues until all the statement/lines of your text file get to read as well as displayed.
    Lastly, you have to close the file.

Scroll Back to Top