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