feof() — Test End-of-File Indicator
Format
#include <stdio.h>
int feof(FILE *stream);
Language Level
ANSI
Threadsafe
Yes
Description
The feof()
function
indicates whether the end-of-file flag is set for the given stream.
The end-of-file flag is set by several functions to indicate the end
of the file. The end-of-file flag is cleared by calling the rewind()
, fsetpos()
, fseek()
, or clearerr()
functions
for this stream.
Return Value
The feof()
function
returns a nonzero value if and only if the EOF flag is set;
otherwise, it returns 0.
Example
This example scans the input stream until
it reads an end-of-file character.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char string[100];
FILE *stream;
memset(string, 0, sizeof(string));
stream = fopen("qcpple/qacsrc(feof)", "r");
fscanf(stream, "%s", string);
while (!feof(stream))
{
printf("%s\n", string);
memset(string, 0, sizeof(string));
fscanf(stream, "%s", string);
}
}