Check if End Of File has been reached: how to use feof : File End « File « C / ANSI-C






Check if End Of File has been reached: how to use feof



#include <stdio.h>

int main ()
{
  FILE * pFile;
  long n = 0;
  pFile = fopen ("my.txt","rb");
  
  if (pFile==NULL) 
      perror ("Error opening file: my.txt");
  else
  {
    while (!feof(pFile)) {
      fgetc (pFile);
      n++;
    }
    fclose (pFile);
    printf ("Total number of bytes in my.txt: %d\n",n);
  }
  return 0;
}

           
       








Related examples in the same category

1.Read and check if the file end has been reached
2.Reads files and displays them on the screen: use EOF
3.Copy a file: how to use feof