【发布时间】:2018-11-30 12:52:28
【问题描述】:
如何使用 scanf 读取带空格的字符串(无需回车)?而且我还希望这个程序在输入为 EOF 时停止。
我使用了以下代码:
int main() //this is not the whole program
{
char A[10000];
int length;
while(scanf(" %[^\n]s",A)!=EOF);
{
length=strlen(A);
print(length,A);
//printf("HELLO\n");
}
return 0;
}
但它正在读取两个 EOF(ctrl+Z) 来停止程序。有人能给我任何建议吗?
【问题讨论】:
-
哦,我可能应该从以下开始:如何“表现得很奇怪”?对于某些指定的输入,它的预期行为和输出是什么?什么是实际行为和输出?另请阅读how to ask good questions 和this question checklist。最后学习如何创建minimal reproducible example。
-
正在读取两个EOF(ctrl+Z)来停止程序
-
不要使用scanf!