I need to read something like:
5 60 35 42
2 38 6
5 8
300 1500 900
And then save the first line in an array. After calling other functions do the same with the next line, and so on.
I try with gets() and then use sscanf() to scan the integers from the string, but I don’t know how to read n numbers from a string.
I’ve seen input files like this for competitions before. If speed is more of an issue than error detection, you could use a custom routine. Here’s one similar to that I use:
It will destroy your memory if there’s more than 100 characters on a line, or more numbers than array can hold, but you won’t get a faster routine to read in lines of unsigned ints.
On the other hand, if you want simple: