function
<cstdio>
feof
int feof ( FILE * stream );
Check end-of-file indicator
This indicator is generally set by a previous operation on the stream that attempted to read at or past the end-of-file.
Notice that stream's internal position indicator may point to the end-of-file for the next operation, but still, the end-of-file indicator may not be set until an operation attempts to read at that point.
This indicator is cleared by a call to clearerr, rewind, fseek, fsetpos or freopen. Although if the position indicator is not repositioned by such a call, the next i/o operation is likely to set the indicator again.
Parameters
- stream
- Pointer to a FILE object that identifies the stream.
Return Value
A non-zero value is returned in the case that the end-of-file indicator associated with the stream is set.Otherwise, zero is returned.
Example
|
|
This code opens the file called myfile.txt, and counts the number of characters that it contains by reading all of them one by one. The program checks whether the end-of-file was reached, and if so, prints the total number of bytes read.
See also
- clearerr
- Clear error indicators (function)
- ferror
- Check error indicator (function)