Function feof () in C

The int feof function (FILE * stream) in the standard Library C checks the end-of-file indicator for the given Stream.

The int feof function (FILE * stream) in the standard Library C checks the end-of-file indicator for the given Stream.

Declare the feof () function in C

Below is the declaration for the feof () function in C:

 int feof ( FILE * stream ) 

Parameters

stream - This is the pointer to a FILE object that identifies the Stream.

Returns the value

This function returns a non-zero value when the End-Of-File Indicator that binds to the Stream is set, otherwise the function returns 0.

For example

The following C program illustrates the usage of the feof () function in C:

 #include int main () { FILE * fp ; int c ; fp = fopen ( "baitapc.txt" , "r" ); if ( fp == NULL ) { perror ( "Da xay ra loi trong khi mo baitapc.txt" ); return (- 1 ); } while ( 1 ) { c = fgetc ( fp ); if ( feof ( fp ) ) { break ; } printf ( "%c" , c ); } fclose ( fp ); return ( 0 ); } 

Suppose we have a baitcap.txt with the following content. This file will be used as an input for our C program:

 Learn more about QTM and more 

Compile and run the above C program to see the results:

According to Tutorialspoint

Previous article: Function clearerr () in C

Next lesson: ferror () function in C

5 ★ | 1 Vote