I am trying to use scanf to capture a string of numbers and convert it into a corresponding array. For example, a user would enter in 1234, then enter, and the following would be set:
array[0]=1
array[1]=2
array[2]=3
array[3]=4
Here is my code so far:
void user_input()
{
int cardarray[16];
int i;
char number;
printf("Enter in the number:");
for (i=0; i<16; i++)
{
scanf("%c", &number);
number = cardarray[i] - '0';
}
printf("The number is %d\n", /*some value*/);
}
I know you have to read characters and convert each into an integer digit, but I'm not exactly sure how.
chars as opposed to using anintand the%dformat specifier?