【发布时间】:2014-04-11 20:50:07
【问题描述】:
每当我调用此函数时,它都会跳过其中的 fgets 语句。
void getString(char *str){ /* Read a string from the keyboard */
fprintf(stdout,"Please enter a string: ");
fgets(str,MAX_STRING_LEN,stdin);
}
这是函数调用
if(strcmp(cmd,"new")==0){ /* new string command */
getString(current);
}
【问题讨论】:
-
你确定它已经被调用了吗?什么是“电流”?你认为它没有被调用是因为调试器(内联?)还是因为它没有输出任何东西?
-
@hacks 我相信你的意思是输出?冲洗
stdin是UB。 -
@FilipeGonçalves;哎呀!删除我的评论:)
-
current其实是一个字符串数组;
-
对不起,但问题是现在,我们所能做的就是推测。请考虑提供所有相关(甚至可能相关)的内容,以便我们给出答案。在这里,另一种猜测:您是否可能拥有重定向的标准输入
stdin?要么通过freopen调用,要么通过在 Linux 终端上做一些我不知道的事情......
标签: c string function-call