The numeric value of a character that represents a number is not that number. Specifically, the char '0'
is of value 48
not 0
, '1'
is 49
not 1
, and so on through '9'
being 57
not 9
. Here's the ASCII table for reference.
You will need to convert the char
value from p
to a number by subtracting 48
from your char
values. You don't have to remember that '0'
is 48
, just that the numeric char
values are in order. This means that you can simply subtract '0'
.
Here's an example of what you'll need to change; you can make other similar changes for other cases.
case '0':
kc[i] = K0[ p[i] - '0' ]; k[0]++;
break;