cd
~steve/ex/parse_int.c
parse_int.c
getchar(3)
isdigit(3)
parse_int
stdin
$ echo 12345 | ./parse_int
num_value
0
'0'
1
'1'
9
ascii(7)
ch - '0'
$ echo 0 | ./parse_int 0 * 7 = 0 $ echo 1 | ./parse_int 1 * 7 = 7 $ echo 12345 | ./parse_int 12345 * 7 = 86415
Recall, 539539539 means 5⋅102+3⋅101+9⋅100=(5⋅101+3⋅100)⋅10+9.5\cdot10^2 + 3\cdot10^1 + 9\cdot10^0 = (5\cdot10^1 + 3\cdot10^0)\cdot10 + 9.5⋅102+3⋅101+9⋅100=(5⋅101+3⋅100)⋅10+9. But notice that the number in the parentheses is just 535353. Therefore, if val is our current value, then after reading in another digit, we need to multiply val by 10 and add the value of the digit.
val
+
$ echo 32527+1256289 | ./parse_int 32527 + 1256289 = 1288816
-
*
/