I keep getting values as long as the user does not enter a positive integer (and I control if user entered negative values or if user entered an integer). I try to do it without using isdigit, it enters an infinite loop when I enter a character.
int quantity;
printf("Please enter term(s) number");
scanf("%d",&quantity);
while( 1){
if(quantity<0){
printf("Please enter “positive” number");
scanf("%d",&quantity);
}
if(!(quantity>='0' && quantity<='9')){
printf("Please enter “a” number");
scanf("%d",&quantity);
}
}
while( 1)is an infinite loop. How to exit it?quantity>='0'will always be false ('0'means ASCII character 0)breakstatement where you are supposed to exit the loop.fgets()for all input and thensscanf()and then, ifsscanf()returns the wrong value, or the entry is the wrong value, you dump the string and ask for another..