C EOF & fclose() function : <stdio.h>Pritesh
EOF and feof function >> stdio.h >> File Handling in C
int feof(FILE *stream);
What it does ?
- 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.
- Once the indicator is set, read operations on the file return the indicator until rewind is called, or the file is closed.
- The end-of-file indicator is reset with each input operation.
Ways of Detecting End of File :
A ] In Text File :
- Special Character EOF denotes the end of File
- As soon as Character is read,End of the File can be detected
- EOF is defined in stdio.h
- Equivalent value of EOF is -1
Printing Value of EOF :
B ] In Binary File :
- feof function is used to detect the end of file
- It can be used in text file
- feof Returns TRUE if end of file is reached
int feof(FILE *fp);
Ways of Writing feof Function :
Way 1 : In if statement :
if( feof(fptr) == 1 ) // as if(1) is TRUE
printf("End of File");
Way 2 : In While Loop
--- - --
--- - --
Bookmark & Share