Well, you can loop through all characters of the string:
char input[8]="02320000";
char output[8];
for(int = 0; i < 8; ++i)
output[i] = input[i] - '0';
Strings in C are just sequences of characters that ends with the so called
'\0'
-terminating byte, whose value is 0. We use char
arrays to store them
and we use the ASCII values for the character.
Note that 1 != '1'
. 1
is the interger one, '1'
is the representation of
the number one. The representation has the value 49 (see ASCII). If you want to calculate
the real number of a character representation, you have to use c-'0'
, where
c
is the character in question. That works because in the table, the values of
the numbers also are ordered as the numbers themselves: '0'
is 48, '1'
is
49, '2'
is 50, etc.