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
Discover more
command in library C running program C parameters in CShare by
Jessica TannerYou should read it
- Function fscanf () in C
- The function gets () in C
- The function sscanf () in C
- Function fputs () in C
- The getchar () function in C
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- The ferror () function in C
- Function fflush () in C
- The function fgetpos () in C