I have a file that has the following format:
abc dca
2
aa bb
casca casss
abc dca
3
aa bb
casca casss
casca casss
abcd abcd
0
Basically it goes by blocks (in the previous example there would be 3 blocks). A particular block would be:
abc dca
2
aa bb
casca casss
In all case we would have:
First line: Always two words separated by a space.
Second line: A number
From here, we would have as many lines as the previous number, and each line would have always two words.
How can I parse a file so that for each block I can call a function passing some stuff that I calculate with what I have found in the block?
There are many ways to do this. The two I thought of are:
If the file is not very large, then you could read it all into a list of strings (one string for each line).
Another way is to pass create a function that takes a file handle and the previous block.
(I do not want to write dynamic arrays in C)
Use a minimal state machine: