I am using c and I am a newbie.
I want to get a input (1 or 2 or 3) and I will give the user suggest;
printf("please do it\n");
printf("1. \n");
printf("2. \n");
printf("3. \n");
char opt;
scanf("%c"&opt");
if opt is not 1 or 2 or 3 then
printf("error\n");
printf("please re do it");
and all is in a while(true) loop until user enter the enter(new line charactor) to exit;
and how to do it?
I tried to create a function.
void get_order(char opt){
switch(opt){
case '1':break;
case '2':break;
case '3':break;
default:
printf("error\n");
printf("please re do it"):
char option;
scanf("%c",&option);
get_order(option);
}
}
but it not work. thank you.
while(true)loop, but there is no such loop in your code. You should provide a complete example (including amainand all included files). See stackoverflow.com/help/minimal-reproducible-examplescanf("%c"&opt");through, turn on more warnings or change to a better compiler.get_int_from_user. That function may be useful for you, in the sense that it keeps reprompting the user for input until the user enters a valid number. However, the part about verifying that this number is between1and3would have to be added by you.