I have to read a txt file with lines formated like this:
1: (G, 2), (F, 3) 2: (G, 2), (F, 3) 3: (F, 4), (G, 5) 4: (F, 4), (G, 5) 5: (F, 6), (c, w) 6: (p, f), (G, 7) 7: (G, 7), (G, 7) w: (c, w), (c, w)
Each line will feed a struct with its data (the 5 numbers or letters in it).
What’s the best way to read the line and get the strings I want?
I’m currently using a long sequence of conditions using fgetc but that seems ugly and not very smart.
I can’t use arrays because the lines may vary in size if the numbers have two digits.
Sample run:
If the last value in the input is more than 10 characters it will be truncated with no indication of error, if this is not acceptable you can use the
%cconversion specifier as a sixth argument to capture the next character after the last value and make sure it is a closing parenthesis.