Feof

From Wikipedia, the free encyclopedia

The correct title of this article is feof. The initial letter is shown capitalized due to technical restrictions.

feof is a C function belonging to the ANSI C standard library, and declared in the file stdio.h. Its primary purpose is to distinguish between cases where a stream operation has reached the end of a file and cases where the "EOF" (End Of File) error message has simply been returned as a default error message, without the end of the file actually being reached.

[edit] Function Prototype

The function is used with syntax as follows:

int feof(FILE *stream_pointer);

It takes one argument: a pointer to the FILE structure of the stream to check.

[edit] Return value

The return value of the function is an integer. A nonzero value signifies that the end of the file has been reached; a value of zero signifies that it has not.

[edit] Example code

   #include <stdio.h>

   int main(int argc, char **argv) {

       FILE *my_file;

       my_file = fopen("file.txt","r");

       while(!feof(my_file)) {
           /* [...End of file not reached, do something with it...] */
       }

       fclose(my_file);

       return 0;
   }