0

I am trying to grab multiple lines of input with scanf, all the lines have the same formatting example line:

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);
user2084666
  • 831
  • 3
  • 9
  • 14

3 Answers3

2

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
}   
mohit
  • 5,696
  • 3
  • 24
  • 37
  • 2
    +1, but I'd completely remove white space from the format string: `"%d,%d:%d:%d,%d,%d"`. The conversion `"%d"` already includes leading whitespace on its own. – pmg Apr 20 '13 at 09:24
0

This scanfs 2 lines:

scanf("%d, %d:%d:%d, %d, %d\n%d, %d:%d:%d, %d, %d", &int1, &int2...)
red_eyes
  • 308
  • 1
  • 3
  • 6
-2

You can try using a for loop. So it would be

for (int i =0; i < NumberOfLines;i++) { scanf(" %d, %d:%d:%d, %d, %d", int1, int2, int3, int4, int5, int6); }