gpt4 book ai didi

c - gets() 内部开关被忽略

转载 作者:太空宇宙 更新时间:2023-11-04 05:43:53 25 4
gpt4 key购买 nike

有人能告诉我为什么 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com