## Recommended Posts

Great_White    148
Hi, is there a way to read a 1-byte number with using scanf() function in C? I think its reading 4byte(int) numbers.

##### Share on other sites
Crypter    748
unsigned chars are guaranteed to be the size of a byte. Because of this, you can simply read in a byte (char) and convert it to an integer.

##### Share on other sites
Great_White    148
so I read it with scanf("%c", &value). After that how can I convert it to integer is there a specific function ?

##### Share on other sites
Antheus    2409
value already is an integer, but it's range is limited to values 0-255.

Or do you mean that your input is '0', '1', '2', ....

I'd usually refer to this as single-digit number, rather than 1-byte.

Easiest way would probably be:
int x = value - '0';