开发者

How to use "enter" to separate input tokens in C?

Example user input:

abcd enter efgh enter

I want to extract the strings separated by presses of t开发者_如何学Che enter key.


What function are you using for read on 0 ? (I guess it's on 0). If it's read(), you normally read byte by byte, so when the user press enter, check if the byte is equal to '\n' (simple quote !).


Use getline it's safe, strongly recommended instead of {f}gets

Or use strtok with '\n' as a delimiter

http://www.gnu.org/s/libc/manual/html_node/Line-Input.html


You could just read whole lines using fgets or scanf

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜