about scanf
Hi,
is there a way to read a 1-byte number with using scanf() function in C? I think its reading 4byte(int) numbers.
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.
so I read it with scanf("%c", &value). After that how can I convert it to integer is there a specific function ?
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:
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';
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement