Hi everyone
I have a simple piece of code thus:
char userChoice = '\0';
validate:;
printf("Please make a choice [y/n] \n"); //fflush (stdout) ;
scanf("%c", &userChoice);
if(userChoice != 'y' && userChoice != 'n' )
{
printf("\nInvalid input; please enter y or n. \n ");
userChoice = '\0';
goto validate;
}
printf("\n %c was your choice. \n ", userChoice ); fflush (stdout) ;
It is working, but the problem I have is that when the goto executes, it seems to do so twice:
Please make a choice [y/n]
j
Invalid input; please enter y or n.
Please make a choice [y/n]
Invalid input; please enter y or n.
Please make a choice [y/n]
n
n was your choice.
I suspect there is something really simple here that I am missing.
Thanks