有人能告诉我为什么 case 1
中的 gets 被完全忽略了吗?
// #define M 50 is at the top
char product[M] = {0};
int choice = -1;
printf("Command: ");
scanf("%d", &choice);
switch(choice){
case 0:
break;
case 1:
printf("Product: ");
gets(product);
insert_product(warehouse, price, product);
break;
case 2:
// print_all();
break;
default:
printf("Scelta non valida\n");
break;
}
最佳答案
gets 可能会被前一个输入的结尾字符跳过。尝试在 gets 之前添加一个 getchar() 以查看是否是问题所在。
关于c - gets() 内部开关被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10840740/