I am doing a very simple homework that requires me to output a file's content, but I unexpectedly reach EOF before doing anything. The file contains just the word "pig" and for some reason EOF returns 16. I am using Dev-Cpp and the program is in C.
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
fp=fopen("C:/Users/myusername/Desktop/numeri.txt", "r");
char c;
if (fp!=NULL)
{
printf ("File opened correctly.\n");
c=fgetc(fp);
printf("%d\n", feof(fp)); //FEOF EQUALS 16 FOR SOME REASON
while (feof(fp)==0)
{
putchar(c);
c=fgetc(fp);
}
fclose(fp);
system("PAUSE");
return 0;
}
else
{
printf ("File cannot be opened.\n");
system("PAUSE");
exit(1);
}
system("PAUSE");
}