I am trying to creating a console program with menu in c. But I have a problem about validating the option int value. When I put char value it accepts it. I am trying to catch this condition. It understands the condition but scanf is not working second time to read input. It just skips. My code below. Thanks for help!
while (true) {
printf("%s", "Choose one option: ");
while (scanf("%d", &choice) != 0) {
puts("This is not a number! Enter again:");
}
// checking input
while (choice < 1 || choice > 8){
puts("Wrong input! You can choose only 1 - 8!");
printf("%s", "Choose one option: ");
scanf("%d", &choice);
}
if (choice == 8)
break;
(*options[choice])();
}