Can someone tell me what's wrong with this:
int main()
{
char a[100];
int i = 0;
printf("Enter a number: ");
scanf("%c", &a[i]);
printf("The number you've entered is: %d", a[i] - '0');
}
Brief summary: I am trying to convert a number stored in a char
array to its int
equivalent. I know in C#, you use the intparse
command, but because there isn't such one in C, I do not know what to do. When I input a two digit number, it is only outputting the first digit, of the input char
.