Home

feof

feof is a function in the C standard library used to test whether the end-of-file indicator for a given FILE stream has been set. It is declared in stdio.h and has the prototype int feof(FILE *stream). The function returns a nonzero value if the end-of-file indicator for the stream is set, and zero otherwise.

The end-of-file indicator is set by input functions when an attempt to read reaches the end of

Usage and caveats: feof should not be used as the primary loop condition to control input. It

Relation to other status checks: feof complements ferror, which tests for read errors. Together, they help distinguish

Overall, feof provides a way to query whether the end of a stream has already been reached,

the
underlying
file.
Once
the
indicator
is
set,
feof
will
report
true
for
that
stream
until
the
indicator
is
cleared.
The
indicator
can
be
cleared
by
clearerr
or
by
repositioning
the
stream
with
functions
such
as
fseek,
fsetpos,
or
rewind.
only
reports
whether
an
end-of-file
condition
has
already
been
encountered
by
a
prior
read
operation.
A
common
pattern
is
to
check
the
return
value
of
the
input
function
(for
example,
fgets,
fread,
fgetc)
and,
when
it
indicates
end-of-file
or
error,
then
consult
feof
to
determine
whether
end-of-file
caused
the
condition,
or
ferror
to
check
for
a
read
error.
among
end-of-file,
error,
and
successful
reads
when
processing
streams.
rather
than
predicting
future
data
availability.