[英]Getting multiple lines of input with scanf() in c
I am trying to grab multiple lines of input with scanf, all the lines have the same formatting example line: 我试图用scanf捕获多行输入,所有行都具有相同的格式示例行:
1, 05:05:04, 1, 1103 1,05:05:04,1,1103
the current code I have grabs only one line 我目前的代码只能抓一行
scanf(" %d, %d:%d:%d, %d, %d", int1, int2, int3, int4, int5, int6);
Are you looking for this? 您在找这个吗?
while (scanf("%d,%d:%d:%d,%d,%d",
&int1, &int2, &int3, &int4, &int5, &int6) == 6) {
//use int1, int2, int3, int4, int5, int6
}
这scanfs 2行:
scanf("%d, %d:%d:%d, %d, %d\n%d, %d:%d:%d, %d, %d", &int1, &int2...)
You can try using a for loop. 您可以尝试使用for循环。 So it would be
原来如此
for (int i =0; i < NumberOfLines;i++) { scanf(" %d, %d:%d:%d, %d, %d", int1, int2, int3, int4, int5, int6); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.