cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstdio (stdio.h) : feof
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdio (stdio.h)
functions:
· clearerr
· fclose
· feof
· ferror
· fflush
· fgetc
· fgetpos
· fgets
· fopen
· fprintf
· fputc
· fputs
· fread
· freopen
· fscanf
· fseek
· fsetpos
· ftell
· fwrite
· getc
· getchar
· gets
· perror
· printf
· putc
· putchar
· puts
· remove
· rename
· rewind
· scanf
· setbuf
· setvbuf
· sprintf
· sscanf
· tmpfile
· tmpnam
· ungetc
· vfprintf
· vprintf
· vsprintf
macro constants:
· EOF
· FILENAME_MAX
· NULL
· TMP_MAX
objects:
· stderr
· stdin
· stdout
types:
· FILE
· fpos_t
· size_t

-

feof function
int feof ( FILE * stream );
<cstdio>

Check End-of-File indicator

Checks if the End-of-File indicator associated with stream is set, returning a value different from zero if it is.
This indicator is generally set by a previous operation on the stream that reached the End-of-File.
Further operations on the stream once the End-of-File has been reached will fail until either rewind, fseek or fsetpos is successfully called to set the position indicator to a new value.

Parameters

stream
Pointer to a FILE object that identifies the stream.

Return Value

A non-zero value is returned in the case that the End-of-File indicator associated with the stream is set.
Otherwise, a zero value is returned.

Example

/* feof example: byte counter */
#include <stdio.h>
int main ()
{
  FILE * pFile;
  long n = 0;
  pFile = fopen ("myfile.txt","rb");
  if (pFile==NULL) perror ("Error opening file");
  else
  {
    while (!feof(pFile)) {
      fgetc (pFile);
      n++;
      }
    fclose (pFile);
    printf ("Total number of bytes: %d\n",n);
  }
  return 0;
}

This code opens the file called myfile.txt, and counts the number of characters that it contains by reading all of them one by one. Finaly the total amount of bytes is printed out.

See also

clearerr Clear error indicators (function)
ferror Check error indicator (function)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us