Reading text file and structuring it..
Ok pretty much a newby in programming in C. Can read some data and put it in structures. Just the basic stuff that I had to do and learn at University. However, I now have to write XML in C. I am left up with a text-file that looks like this. Btw..This is not home work!! I graduated long time ago.. :cool:
Anyway..
************ the text file ***********************
junk
junk
Header containg 21 lines of junk which are of no interest.
junk
junk
/* now come the more interesting stuff */
xx. CF: 5740W (5345W - 6033W)
information which also has to be stored and is variable in size.
xx. CF in CA: 6312E (6222W - 6302W)
Again some information.
xx. CAC: 5848W
etc. etc.
/* this goes on for some 40 times. Sometimes there is info, and sometimes there is not. There is however always a "xx. " that states the beginning of something important. */
What I want this program to do is that it reads the text above, and parses it in to some variables. For example I shall parse the first 2 lines, to just let you see what I actually mean.
************* the first two lines ****************
xx. CF: 5740W (5345W - 6033W)
information which also has to be stored and is variable in size.
********************************************
The first "xx. " can be treated as &junk.
"CF in CA" is a variable and should be remembered as like for example cmlist[i]CM_NAME
": " again &junk
"57" is an y-position, and should be remembered as cmlist[i]CM_Y
"40" is an x-position, and should be remembered as cmlist[i]CM_X
"W" is a variable.. it can be E(=east) or W(=west).. it matters because I then know whether to multiply cmlist[i]CM_X with 1 or -1.
" (5345W - 6033W)" Can be treated as junk.
Then we should go to the next line.
If there is information then cmlist[i]CM_TAG should be set at 1, else at 0.
If CM_TAG is equal to 1, then "information which also has to be stored and is variable in size." should be stored in cmlist[i]CM_INFO.
Then we are finished and can raise [i], and do the whole thing again... In this program only 30 to 40 i's are needed.
scanln and scanf are pretty much new to me. I do have the book of Kernighan and Ritchie, but it does not help me that much on reading text when it is not structured like expected. I do not expect anyone of you to write a C-program that does the above, however.. a start and some hints or tips would be very very welcome.
Kind regards,
Killroy