gpt4 book ai didi

c - getc(stdin) 后程序停止工作

转载 作者:行者123 更新时间:2023-11-30 19:37:39 25 4
gpt4 key购买 nike

printf("hello2");
int i = 0;
int done = 0;

while (!done)
{
char c;
printf("hello3");
c = getc(stdin);
printf("hello4");
if (isspace(c))
{
done = 1;
ungetc(c, stdin);
printf("hello5");
}
}

所以我的程序当前正在尝试读取输入(在本例中具体为空输入)。然而,在我发现我的程序不起作用之后,我尝试通过分散 printfs 来调试它,在我看来,在 c = getc(stdin) 之后,程序停止工作?如果我的理论是正确的,那么使用 c = getc(stdin) 有什么问题吗?

最佳答案

您是否尝试过在空格后按 Enter 键?除非您进行特定安排,否则您的终端仿真或运行程序的任何位置都不会为您提供输入的每个键盘字符。它会一直等到您按 Enter 键,然后让您处理所写入的整行。

关于c - getc(stdin) 后程序停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39381451/

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