If you don't mind using char
as the array element type, you can use snprintf()
:
char digits[32];
snprintf(digits, sizeof(digits), "%d", number);
Each digit will be represented as the character values '0'
though '9'
. To get the integer value, subtract the character value by '0'
.
int digit_value = digits[x] - '0';