How to convert a character into an integer array?

Consider :
char *n=123456;

I want to convert it into:
int b[]={1,2,3,4,5,6};
i.e.
b[0]=1;
b[1]=2;
.....
b[5]=6;

Please suggest the code to perform the same.
Thank you....
Surely you meant char* n = "123456";..
What you need to do is loop through n until n[i] is a 0. For each other char found that way, b[i] = n[i]-'0';
Thanks for the reply............
but why are we subtracting 0 as a character?
Each char has a value. The value of the charachter '0' is not 0 (it's 48 iirc). The digits 0 to 9 are sequential, thus |4| is |0|+4. This can be used to translate digits to chars and back.

The same trick can be applied if you wish to encode words as numbers. If 'a' is encoded as 0, then any other letter's value can be found by deducting 'a' from it.
Topic archived. No new replies allowed.