Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
用户输入示例:
abcd enterefghenter
我想提取由enter按键分隔的字符串。
您在 0 上使用什么功能进行读取?(我猜它是0)。如果是 read(),通常是逐字节读取,所以当用户按下回车键时,检查字节是否等于 '\n'(简单引号!)。
使用getline它是安全的,强烈推荐而不是 {f}gets
getline
或使用strtok'\n' 作为分隔符
strtok
http://www.gnu.org/s/libc/manual/html_node/Line-Input.html
您可以使用fgets或阅读整行scanf
fgets
scanf