feof function tells if the file pointer is at the end of the file

Syntax

C feof function has the following format.

int feof(FILE *stream);

C feof function is from header file stdio.h.

Description

C feof function determines whether the end of the file has been reached.

C feof function returns a nonzero value if the file pointer is at the end of the file. C feof function returns zero otherwise.

Example

Tell if the file pointer is at the end of a file by using C feof function.


#include <stdio.h>
#include <stdlib.h>
/* w  ww  .  jav  a2s. c  o m*/
int main(void){
   FILE *fp;

   if((fp=fopen("test", "rb"))==NULL) {
      printf("Cannot open file.\n");
      exit(1);
   }

   while(!feof(fp)) {
      char ch = getc(fp);
      printf("%c",ch);
   }

   fclose(fp);
}




















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h