Fgetc always returns 1
the following function exists:
void readAndPrint(FILE * f) {
int c;
while(c = fgetc(f) != EOF) {
printf("%d", c);
}
}
Basically () I used the following code to use the specified function:
FILE * pFile;
pFile=fopen ("myfile.txt","r");
readAndPrint(pFile)
;
No matter what I put in myfile.txt, the program prints them. For example, for abc, 111 is printed.
I know that the c in the function must be declared int in order to compare it correctly with EOF. Also, I expected the int from the ASCII set for each char to be printed in a text file (97 for a, ...). I can't figure out why it prints "those" ... Do you know why? Thank you in advance.
+3
source to share