开发者

How to read char as a number

开发者 https://www.devze.com 2023-02-28 16:20 出处:网络
This is really simply i know... unsigned char var = 11; ... fprintf(plik, \"%c\", var); Then I want to read:

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

精彩评论

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