I want a menu from which you choose some action.
Problem is that when we choose one, and press the "return" key, the user input command which should have been the next step, is skipped. Why is that ?
The code is :
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int choice;
do
{
printf("Menu\n\n");
printf("1. Do this\n");
printf("2. Do that\n");
printf("3. Leave\n");
scanf("%d",&choice);
switch (choice)
{
case 1:
do_this();
break;
case 2:
// do_that();
break;
}
} while (choice != 3);
return(0);
}
int do_this()
{
char name[31];
printf("Please enter a name (within 30 char) : \n");
gets(name); // I know using gets is bad but I'm just using it
// fgets(name,31,stdin); // gives the same problem by the way.
// Problem is : user input gets skiped to the next statement :
printf("Something else \n");
return(0);
}