Previous | Home | Next |
Description
The C library function, The feof function is 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.
Declaration
Following is the declaration for feof() function.
int feof(FILE *stream)
Parameters
stream - Macro tests if end-of-file has been reached on a stream. feof is a macro that tests the given stream for an end-of-file indicator.
Return Value
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; }
Output
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.
Previous | Home | Next |