I' am using goto statement inside switch statement to take the input from the user one more time if its Invalid. Here is the code
#include<stdio.h>
int main(void)
{
int choice;
input:
printf("Enter Your Choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
/* do something */
break;
case 2:
/* do something */
break;
case 3:
/* do something */
break;
default:
printf("Invalid Input");
goto input;
}
}
code works just fine when the input is numeric. But when I enter alphabet or some character code runs infinitely as if scanf is not there. I could not understand this behaviour.Why is it happening that way?