读取输入的多行与scanf()的 [英] Reading multiple lines of input with scanf()
本文介绍了读取输入的多行与scanf()的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
相关code片断:
char input [1024];
printf("Enter text. Press enter on blank line to exit.\n");
scanf("%[^\n]", input);
这将读取整条生产线,直到用户点击[进入],$ P $进入第二行(如果他们愿意的话)。pventing用户
That will read the whole line up until the user hits [enter], preventing the user from entering a second line (if they wish).
要退出,他们按[Enter],然后再次[Enter]键。所以,我想)涉及新行转义序列while循环,for循环,如果周围的scanf函数语句的各种(但似乎没有任何工作。
To exit, they hit [enter] and then [enter] again. So I tried all sorts of while loops, for loops, and if statements around the scanf() involving the new line escape sequence but nothing seems to work.
任何想法?
推荐答案
试试这个:
while (1 == scanf("%[^\n]%*c", input)) { /* process input */ }
这篇关于读取输入的多行与scanf()的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文