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.

int feof(FILE *stream)

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

int main()
FILE *filee = NULL; 
char buf[50]; 
filee = fopen("infor.txt","r"); 
             fgets(buf, sizeof(buf), filee); 
    return 0; 

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

  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