I know strings are essentially just arrays of characters, so what would be the easiest way to take each individual digit and put it into a separate space in an array?
ex.) *str = "90210"
array[0] = 9
array[1] = 0
array[2] = 2
array[3] = 1
array[4] = 0
all my attempts at achieving this just result in an array full of garbage numbers
what ive done is:
Code:
int *array;
array = malloc(sizeof(int)*(strlen(str));
for(i=0; i<strlen(str); i++)
{
array[i] = str[i]
}
any help with this would be greatly appreciated.
also, I should mention that the string will be defined in main, and its converted into an array in a separate function.