I have a char*
string of only exactly 5 digits. I want to convert this string to a integer array.
I've tried this:
#include <stdio.h>
#include <string.h>
int main()
{
int numbers[5];
const char* titleid = "TEST00411";
const char* digits = titleid + 4;
for (int i = 0; i < 5; ++i) {
numbers[i] = digits[i];
printf("LOOP: %d\n", digits[i]);
}
printf("%d\n", numbers[0]);
printf("%d\n", numbers[1]);
printf("%d\n", numbers[2]);
printf("%d\n", numbers[3]);
printf("%d\n", numbers[4]);
return 0;
}
Output:
LOOP: 48
LOOP: 48
LOOP: 52
LOOP: 49
LOOP: 49
48
48
52
49
49
Why aren't the numbers displayed correctly (0, 0, 4, 1, 1)?