C - ¿Se omite la entrada del usuario?
Quiero un menú del que elijas alguna acción.
El problema es que cuando elegimos uno y presionamos la tecla "retorno", se omite el comando de entrada del usuario, que debería haber sido el siguiente paso. Porqué es eso ?
El codigo es:
#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);
}