Chapter Contents

Previous

Next
feof

feof



Test for End of File

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
IMPLEMENTATION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


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


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.