0

I have this code here but the program is all the time saying that the input isn't a number, even if I enter a digit between 1 and 10. Could you help me to find why? Thanks

int main (void){

int iUserImput = 0;

printf("\nEnter a number between 1 and 10: ");

scanf("%d", &iUserImput);

if (isdigit(iUserImput) == 0)

printf("\nThat wasn't a number\n");

else

printf("\nThat was a number\n");

}

0

Recall from Week 2->Walkthroughs->ascii-0 David's discussion of the mapping between numbers and letters. (If you haven't seen it, now would be a good time, and ascii-1 too). The characters '0', '1', ....., '9' have similar mappings. They are represented in ascii as 48, 49, ......, 57. You might find this chart helpful. And remember, isdigit() checks for a digit between 0 and 9.

1
  • Thanks :), I wasn't seeing that isdigit reacts to characters instead of integers.
    – JLDG
    May 28 '16 at 22:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .