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
精彩评论