about scanf

Started by
2 comments, last by Antheus 16 years, 1 month ago
Hi, is there a way to read a 1-byte number with using scanf() function in C? I think its reading 4byte(int) numbers.
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."A. Einstein
Advertisement
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 ?
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."A. Einstein
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';

This topic is closed to new replies.

Advertisement