I am trying to validate user input. Here’s the code:
do{
NSLog(@"Please select from the following options: D/ W/ T/ Q");
res = scanf("%c", &s1);
if(res ==0) {
NSLog(@"Invalid entry.");
}
}while (res ==0);
I want to improve the above code such that it will not allow the user to input anything (such as a number, a string, or any negative number) but only one single character (to be specific, only one of the option given in the prompt).
The current code doesn’t do that.
You can use this code.
Just check it out.