C 中扫描包含空格的字符串
在我的代码中:
scanf("%s", &text);
printf("%s\n", text);
输入:
hi how are you
输出:
hi
而不是
hi how are you
我能做什么来修复它?
In my code:
scanf("%s", &text);
printf("%s\n", text);
Input:
hi how are you
Output:
hi
and not
hi how are you
what can I do to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看 fgets
Look at fgets
我想您正在寻找
Which will read up to a newline delimiter.或者如果您使用其他分隔符
I suppose you're looking for
Which will read up to a newline delimiter. Or if you're using some other delimiter
使用 fgets 获取您的输入:
Use fgets to get your input: