0

As in reading "117" in a text file and giving the variable value 'u', not '1'. And I know I can do it simply and quickly by reading the value to an int and then casting it to unsigned char, I just need to know if I can do it directly.

1 Answers1

2

Try scanf with format specifier hhud (cf. scanf format specifiers at cplusplus.com)

unsigned char c;
scanf("%hhud", &c);

In the terminal, I enter 117, and variable c then shows value 'u' in the debugger...

Stephan Lechner
  • 34,891
  • 4
  • 35
  • 58