I\'m trying to read unknown number of integers by this piece of code:
while (1) {
int c = getchar ();
if (c == EOF)
break;
el
c - '0'
is a rudimentary way of turning a single ASCII digit into an integer.
For example, if c
is equal to '9'
, then its integer value is 0x39
. The ASCII value for '0'
is 0x30
, so, 0x39-0x30 == 0x09
which is equal to the integer value 9
.
Here is the ASCII table for digits:
chr hex dec
'0' 0x30 48
'1' 0x31 49
'2' 0x32 50
'3' 0x33 51
'4' 0x34 52
'5' 0x35 53
'6' 0x36 54
'7' 0x37 55
'8' 0x38 56
'9' 0x39 57