fgetc() - returning (int) 54 instead of (char) 6

Nov 16, 2011 at 12:22pm
Hi

I am a newbie, hope someone can help me.

(Section 1)
I have a text file with one line of numbers: 6123456123456123


(Section 2)
Here is my code to read and print the file:

FILE *fp = fopen("myFile.txt", "r");
int firstInt;
int counter = 6
firstInt = fgetc(fp);
printf("First character of this text file is: %i", firstInt)

if (firstInt == counter)
printf("firstInt equal counter"); // <<< This part is important for me, I want to be able to compared firstInt to counter and if similar print this line.


(Section 3)
Output: First character of this text file is: 54

(Section 4)
My question: why is the return int 54 instead of 6? Obviously it will not print the second line for the reason stated before.

Really hope someone can help me.

Thanks
Dave




Last edited on Nov 16, 2011 at 12:24pm
Nov 16, 2011 at 12:43pm
The ASCII value of 6, is 54
Last edited on Nov 16, 2011 at 2:35pm
Nov 16, 2011 at 7:50pm
Thanks whitenite1.
Topic archived. No new replies allowed.