On this page
feof
Prev: fflush | Up: stdio.h | Next: ferror
Rel: stdio.h, stdio.h & File I/O Guide
Ref: cppreference — feof
Tags: #public #prog #c #stdlib #stdio #tier/standard
Include
#include <stdio.h>
Signature & Overview
int feof(FILE *stream);
Returns non-zero if the end-of-file indicator has been set by a previous failed read.
Notes & Pitfalls
- Never write
while (!feof(f))!feof()only becomes true after a read attempt hits EOF—loop directly onwhile (fgets(...) != NULL)orfread() > 0, then checkfeof()/ferror()afterward.
Example
#include <assert.h>
#include <stdio.h>
int main(void) {
FILE *f = tmpfile();
char buf[8];
assert(fgets(buf, sizeof(buf), f) == NULL && feof(f));
fclose(f);
}
Linked from
Related notes
- tuts/c/stdlib/stdio/ferror Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fflush Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib
- tuts/c/stdlib/stdio_and_file_io Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdio/fclose shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fgets shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fopen shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fprintf shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fputs shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fread shared tags: #c, #prog, #stdio, #stdlib, #tier