feof -- Test for End of File

SYNOPSIS

 #include <stdio.h>

 int feof(FILE *f);
 

DESCRIPTION

feof tests whether the stream associated with the FILE object addressed by f has reached end of file.

RETURN VALUE

feof returns 0 if the file is not positioned at end of file, or nonzero if the file is at end-of-file.

End of file is not detected until an attempt is made to read past end of file, and a call to fseek or fgetpos always resets the end of file flag.

IMPLEMENTATION

feof is implemented as an inline function. The function includes a test for a NULL FILE pointer and for a stream that failed to open. If you #define the symbol _FASTIO, either explicitly or using the compiler define option, an alternate function is used. This version of feof bypasses these error checks, so it executes faster.

EXAMPLE

Use feof to determine the end of a file opened for reading.
  #include <stdio.h>

  main()
  {
    FILE *fp;
    char c;
    int count;

    fp = fopen("tso:MYFILE", "r");
    count = 0;
    while (!feof(fp) && !ferror(fp)) {
       c = getc(fp);
       ++count;
    }

    printf("The number of characters in the file 'MYFILE' was %d.n",
           count-1);
  }

 

RELATED FUNCTIONS

ferror

SEE ALSO


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.