包括扫描用C空格的字符串 [英] Scan a string including spaces in C
本文介绍了包括扫描用C空格的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的code:
scanf("%s", &text);
printf("%s\n", text);
输入:
hi how are you
输出:
hi
而不是
hi how are you
我能做些什么来解决这个问题?
what can I do to fix it?
推荐答案
在与fgets()函数读取至多一个
小于字符数
用n来自给定流指定
并且将它们存储在字符串中
s.Reading停止时换行
字符被发现,在档案结尾或
错误。换行,如果有的话,是
保留。如果有任何字符阅读
并没有错误,一个'\\ 0'
字符被附加到结束
字符串。
The fgets() function reads at most one less than the number of characters specified by n from the given stream and stores them in the string s.Reading stops when a newline character is found, at end-of-file or error. The newline, if any, is retained. If any characters are read and there is no error, a `\0' character is appended to end the string.
这篇关于包括扫描用C空格的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文