I have a file that lists information that I want to store in a struct. It is organized like this:
[
Label
Data
Designation
(these three blank lines are purposely there)
]
(
Type-#
Type-#
...
)
There will be an unknow number of these two different types of listings. They are all in one file, with all the [ blah blah] coming before the ( blah blah ).
So, I want to read the file in, each line at a time, putting the results in a struct. My struct will have a place for the label, data, designation and another for the types and numbers. The numbers have to correspond with the types. How can I have my program run through the file and sort out the data?
I assume fgets would be the best, but how do i stop it from going past the \n and putting the next line in the stuct i am trying to populate? Also, how do i have it skip the blank lines in the [ blah blah ] listing?
Also, how do I parse out the Type from the # in the second part?
I will be needing an array of structs for each part, I assume, but I really just need to know the best way of taking in the data and storing it in my struct.
So I basically need to
First, skip everything until you hit the opening bracket: [
Then read one line into X
The second line goes into Y
The third line goes into Z
Then you skip everything until you run into: ]
Then you skip everything until you run into: (
Now you read each line, putting the first portion of it into A, and the second into B.
You repeat this until you run into the terminator, ).
So Im going to be using a loop I assume, but how do i do the skipping? I know Ill use fgets to get the strings, but beyond that im not sure
Thanks in advance,
Evan
[
Label
Data
Designation
(these three blank lines are purposely there)
]
(
Type-#
Type-#
...
)
There will be an unknow number of these two different types of listings. They are all in one file, with all the [ blah blah] coming before the ( blah blah ).
So, I want to read the file in, each line at a time, putting the results in a struct. My struct will have a place for the label, data, designation and another for the types and numbers. The numbers have to correspond with the types. How can I have my program run through the file and sort out the data?
I assume fgets would be the best, but how do i stop it from going past the \n and putting the next line in the stuct i am trying to populate? Also, how do i have it skip the blank lines in the [ blah blah ] listing?
Also, how do I parse out the Type from the # in the second part?
I will be needing an array of structs for each part, I assume, but I really just need to know the best way of taking in the data and storing it in my struct.
So I basically need to
First, skip everything until you hit the opening bracket: [
Then read one line into X
The second line goes into Y
The third line goes into Z
Then you skip everything until you run into: ]
Then you skip everything until you run into: (
Now you read each line, putting the first portion of it into A, and the second into B.
You repeat this until you run into the terminator, ).
So Im going to be using a loop I assume, but how do i do the skipping? I know Ill use fgets to get the strings, but beyond that im not sure
Thanks in advance,
Evan
