If I understand you correctly, you have input lines like
[0,0]
[0,2]
[0,4]
and you are successfully reading them using a fscanf
call like
fscanf(ifp, " [%d,%d]", &row, &col);
If that's so, and if you have another input format
[0,0]->[0,1]->
[0,2]->[0,3]->
[0,4]->[1,4]->
why can't you just use something like
fscanf(ifp, " [%d,%d]->[%d,%d]->", &row1, &col1, &row2, &col2);
I suppose you could also use
fscanf(ifp, " [%d,%d]->", &row, &col);
which would require two calls to read each line.
P.S. Obligatory scanf
reminders:
Remember to always check the return value from scanf
and fscanf
to make sure the expected inputs were matched. (I conspicuously failed to follow this advice in the code fragments in this answer.)
Even though it often seems like the thing to use, fscanf
is usually a poor tool for the job, and it can be more trouble than it's worth to get it do do what you actually want. You can consider using alternatives.