How to print an unsigned char in C?

Anton picture Anton · Apr 1, 2013 · Viewed 238.7k times · Source

I am trying to print char as positive value:

char ch = 212;
printf("%u", ch);

but I get:

4294967252

How I can get 212 in the output?

Answer

user1944441 picture user1944441 · Apr 1, 2013

Declare your ch as

unsigned char ch = 212 ;

And your printf will work.