feof(3C)
_________________________________________________________________
feof macro
Determine if you have reached the end of a file.
_________________________________________________________________
Calling Sequence
#include <stdio.h>
FILE *fp;
int eofset;
eofset = feof(fp);
Description
Use the feof macro to determine if you have reached the end of
file. Since feof is a #define macro, you will receive error
messages if you declare it as a function.
Returns
The feof macro will return 1 when it encounters an end-of-file
condition.
Example
/* Program test for the feof() macro */
#include <stdio.h>
FILE *fopen(), *fp;
char c;
int i = 1;
main(argc, argv)
int argc;
char *argv[];
{
while (i < argc) {
fp = fopen(argv[i], "r");
for (;;) {
c = getc(fp);
if (feof(fp))
break;
putchar(c);
}
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
feof(3C)
printf("eofbit = %d.\n", feof(fp));
fclose(fp);
i++;
}
return 0;
}
If you call the program test with the files a, b, and c where the
three files contain respectively
This is the first line.
This is a second line of text.
This is the third and last line.
you generate the output
This is the first line.
eofbit = 1.
This is a second line of text.
eofbit = 1.
This is the third and last line.
eofbit = 1.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)