int valid = 0;
while (!valid) {
printf("\nEnter number of characters (1-30)> ");
scanf("%d", & n);
printf("\nInclude numbers (Y/N)> ");
scanf(" %c", & nf);
printf("\nInclude symbols (Y/N)> ");
scanf(" %c", & sf);
//cond1 and cond2 initialized here
if (cond1 && cond2)
valid = 1;
else
printf("Invalid input");
}
I need to implement a faulty input detection functionality for the first integer scan. If the user enters a character instead of an integer the second scanf is skipped and it goes directly to the 3rd scanf. How can I stop this from happening in case of a character input on %d? I want to ask for the input again if the user enters a character instead of a number