简体   繁体   English

您如何忽略输入行的其余部分并从下一条输入行开始恢复?

[英]How do you ignore the rest of an input line and resume starting from the next input line?

I just started learning C. How do you ignore the rest of an input line and resume on the next input line? 我刚刚开始学习C。如何忽略输入行的其余部分,然后在下一条输入行继续? For example: 例如:

Input: 输入:

123456789123456789
hello how are you 

Output: 输出:

123456
hello h

Short answer is you can't. 简短的答案是你不能。 When working with input, especially command line and or program input. 使用输入时,尤其是命令行和/或程序输入时。 You have to process it, argument by argument, line by line. 您必须逐个参数地,逐行地处理它。

I would suggest that you use delimiters ("$","\\n","&") to better manage your input. 我建议您使用定界符(“ $”,“ \\ n”,“&”)更好地管理输入。

I'm really not sure what's your question, but do you mean something like this? 我真的不确定您的问题是什么,但是您的意思是这样的吗?

scanf("%6s%*[^\n]", string);
scanf("%*c%6s", string + 6);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM