Syntax
#include <stdio.h> int feof(FILE *stream);Description
feof 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 rewind, fsetpos, fseek, or clearerr for this stream.
feof returns a nonzero value if and only if the EOF flag is set; otherwise, it returns 0.
This example scans the input stream until it reads an end-of-file character.
#include <stdio.h> int main(void) { char inp_char; FILE *stream; stream = fopen("feof.dat", "r"); /* scan an input stream until an end-of-file character is read */ while (0 == feof(stream)) { fscanf(stream, "%c", &inp_char); printf("<x%x> ", inp_char); } fclose(stream); return 0; /**************************************************************************** If feof.dat contains : abc defgh The output should be: <x61> <x62> <x63> <x20> <x64> <x65> <x66> <x67> <x68> ****************************************************************************/ }Related Information