Checking input in a while loop...
This is what I have for this particular function so far...
Code:
unsigned long getNum(char prompt[80])
{
unsigned long darts;
printf("%s", prompt);
while((scanf("%lu", &darts)) != 1)
{
printf("\n\nThis is not an acceptable entry. please try again.\n");
printf("%s", prompt);
}
return darts;
}
it works perfectly fine if I enter a number. but if i enter a character or letter or something, i was expecting it to reprompt, but instead it goes into an infinite loop of prompting and error messages. Can someone explain why? How can I fix it?