HP C/iX Library Reference Manual (30026-90004)
Chapter 5 145
HP C/iX Library Function Descriptions
feof
feof
Tests whether the end-of-file indicator for a stream has been set.
Syntax
#include <stdio.h>
int feof (FILE *
stream
);
Parameters
stream
A pointer to a file to be tested.
Return Values
=0 End-of-file has not been set.
≠0 End-of-file has been set.
Description
The feof function is intended to clarify ambiguous return values from standard I/O
functions.
The feof function returns a nonzero value if the end-of-file indicator was set on the
specified
stream
. It does not reset the indicator. You need to use the clearerr function to
reset it.
Because I/O functions return EOF for end-of-file and error conditions, you can use feof()
and ferror() to distinguish between them. Also, some systems support I/O functions that
take integer data instead of characters. For these functions, you need to use feof() and
ferror() to differentiate between valid data and the EOF flag.
Example
The following program uses feof():
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[ ];
{
int c;
FILE *dfile, *datale, *datagt;
if(argc != 2) {
fprintf(stderr, "usage: intsort filename\n");
exit(1);
}
dfile = fopen(argv[1], "r");
if(dfile == NULL) {