开发者

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

开发者 https://www.devze.com 2023-02-06 15:02 出处:网络
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

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

精彩评论

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