[英]Reading a specific input format in C
I need to read all N numbers in a line in an array where N is unknown. 我需要读取N个未知数组中一行中的所有N个数字。 When a newline is encountered, read the next X numbers in another array.
遇到换行符时,读取另一个数组中的下一个X数字。 X is also unknown.
X也未知。
The input is in the format:- 输入的格式为:-
1 2 3 4 5 .. to N (store in array A) 1 2 3 4 5 ..至N(存储在数组A中)
1 2 3 4 .. to X (store in array B). 1 2 3 4 ..到X(存储在数组B中)。
How to take the input for this case? 在这种情况下如何接受输入?
you can try 你可以试试
while ( scanf(" %d%c", &num, &ch) == 2 )
{
if ( ch =='\n') break;
// to do :: store or whatever you want
}
it read untill get newline. 它读取直到获得换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.