-
int array question
hi everyone.I want to make a int array which stores imaginary integer like 512 and each digit have a different adress.Let me give an example since my english not enough to explain it.
int example_array[3];
int example_number;
example_number=512;
I want to arrange it like example_number[0]=5 example_number[1]=1 and example_number[2]=2.
Is it possible ?
-
Looks like you need a char [] instead of an int [].
-
Sounds like you're looking for something like this:
Code:
int n = 512;
int a[10];
int i = 0;
while (n > 0) {
a[i++] = n % 10;
n /= 10;
}
However, this has the digits in the opposite order than you've shown. And note that you'd have to change this somewhat to work for n <= 0.