开发者

How to read char as a number

This is really simply i know...

unsigned char var = 11;
...
fprintf(plik, "%c", var);

Then I want to read:

fscanf(plik, "%c", &var);

And the variable doesn't have开发者_开发百科 the proper value. I tried %d but I had an error.


A char is always a 8-bit number. printf will interprete is as an ascii char or an integer based on the format.


Not sure what you're asking. If you want to print the variable as the number 11 then simply:

printf("%d\n", var);

If you want to read it into an int then:

int a;
fscanf(plik, "%c", &a);
printf("%d\n", a);

If you are not reading the value correctly after writing it then maybe you want to fseek one position backwards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜