How to fix infinite loops when user enters wrong data type in scanf()?
问题 C beginner here. For the program below, whenever the user inputs a character or a string it enters an infinite loop. How would you fix this while still using scanf? And what would be the better methods of writing this program rather than using scanf? Thanks to those who will answer. #include <stdio.h> #include <ctype.h> int main() { int rounds = 5; do { printf("Preferred number of rounds per game. ENTER NUMBERS ONLY: "); scanf("%d", &rounds); } while(isdigit(rounds) == 0); return 0; } 回答1: I