# Thread: Verifying single digit input

1. ## Verifying single digit input

I was waondering if anyone could tell me how to verify a single digit input. I've been able to catch an Alpha and also a number greater than nine and less than zero but just can't seem to put the two together. This is a school assignment and we've been told that verification is not necessary but this has really been bugging me.

2. Verify what? Why can't you use isdigit?

3. Or even better, isalnum.

Quzah.

4. I thought he wanted to check whether the input was a digit or not.

Did you read my PM by the way?

5. Thanks for the quik reply. I'm afraid your dealing with a complete n00b here. I tried that but was probably running into 'type' problems. If I understand it right this requites a char argument, right. and returns a 1 if true

6. I think a light has come on. If I use isdigit and also want catch a double digit I need to use a sting and test the second character as well. Am I getting close?

7. Thanks for your help and letting me ramble. I think I got it. This seems to work

Code:
```#include <stdio.h>

int main()
{
char num[10];
int test = 0;

printf ("Enter a single digit:> ");
scanf("%s", &num);
while (test == 0) {
if (isdigit(num[0])&&(num[1]==NULL)) {
printf("The number you entered was %c.\n", num[0]);
test = 1;
}
else {
printf("Not a single digit\nTry again:> ");
scanf("%s", &num);
}
}
system("PAUSE");
return(0);
}```

8. This is wrong in a scary way:
Code:
`num[1]==NULL`
NULL should only be used when dealing with pointers. It's confusing because you hear strings are "null-terminated". Well, in that case it's talking about the ASCII value 0, not the NULL macro definition, which is generally defined as (void *)0. Any of these alternatives would be a whole lot better:
Code:
```!num[1]
num[1]==0
num[1]=='\0'```

9. Thankyou