Currently if this code is run and the user inputs the number 1 or 2 followed by any amount of characters it will take the value 1 or 2 and run. I would like ths case (Number,Char) to be returned as an error. How might this be achieved?
This code is asking the user for a menu selection of either 1 or 2, scaning it into the int menu_choice and then checking it for errors.Code:do { printf("Please Enter Your Choice From The Menu: "); error = scanf("%d",&menu_choice); fflush(stdin); } while ( error == 0 || menu_choice < 1 || menu_choice > 2 );
I know fflush(stdin); is not the correct way to flush the input but i am willing to run with it.
Thanks in advance!



LinkBack URL
About LinkBacks



