feof Function

feof <stdio.h>

int feof( FILE * );
Description:

Used to determine if the end of the file (stream) specified, has been reached. When a file is being read sequentially one line, or one piece of data at a time (by means of a loop, say), this is the function you check every iteration, to see if the end of the file has come.

Return Values:

Nonzero (true) if the end of file has been reached, zero (false) otherwise.

Example:
#include <stdio.h>

int main(void)
{
    char buffer[256];
    FILE * myfile;
	
    myfile = fopen("some.txt","r");
	
    while (!feof(myfile))
    {
        fgets(buffer,256,myfile);
        printf("%s",buffer);
    }
	
    fclose(myfile);
    
    return 0;
}

This example opens a file called some.txt for reading, then in a loop, reads lines from the file and outputs them to the screen. The loop continues until the end of the file has come.

top
Home / Return to Function Reference