how to write these info to file?

J

jeff_zhang446

Hi,
I try to write some data structure into a file as below and would
appreciate if someone can give me some advice here.

row(1) 100 1 0 0 0 0 0 0 0 1
row(2) 150 5 0 0 0 0 0 0 0 2
row(3) 160 7 0 0 0 0 0 0 0 3

row(4) 100, 160.0, 120.0,100.0, 1
row(5) 1, 0, 12, 12, 12, 12, 12, 2
row(6) 0.0, 1.0, 1.5, 1.8, 2.0 3
row(7) 1, 1, 1, 1, 1, 1; 4
row(8) 150, 98.0, 25.0, 56.0, 5
row(9) 0.8, 0.8, 0.9, 10, 12, 15, 6
row(10) 2.6, 8.7, 8.9, 6.5, 7.9; 7
row(11) 160, 46.0, 67.0, 86.0, 8
row(12) 5.8, 9..0, 7.6, 23, 45, 67; 9

note:row(i) - for reference only and will not be included in the output
file.

There are :
1. two categories in the file: row1-row3 and row4-row11.
2. 3 types here: 100 (row1), 150(row2) and 160(row3).
3. the last column of each of the line refers to the row number that
print on the file.
4. 2nd column of row(1)- row(3) is the row number as in(3) relate to
its type in category 2.
Eg: 2nd column type 100 in row(1) =1, which is same as the last
column value as in row(4).
2nd column type 150 in row(2) =5, which is same as the last
column value as in row(8)

A. First I read the type 100 and write part of the info in row(1).
Then I need to jump to category 2 to continue writing the other info
relate to it (row(4) tp row(7)).

B. I jump back to row(2) working on type 150. From (A), I know that the
value I am going to print for the column2 is 5. Continue writing the
info, jump to category 2....

C. same as above.

I wonder how actually can I jump up and down writing all the info into
a file?

In what way I can do that? More importantly I do not how many lines I
need for each type in category 2.

thank you

jeff
 
M

Mike Wahler

Hi,
I try to write some data structure into a file as below and would
appreciate if someone can give me some advice here.

row(1) 100 1 0 0 0 0 0 0 0 1
row(2) 150 5 0 0 0 0 0 0 0 2
row(3) 160 7 0 0 0 0 0 0 0 3

row(4) 100, 160.0, 120.0,100.0, 1
row(5) 1, 0, 12, 12, 12, 12, 12, 2
row(6) 0.0, 1.0, 1.5, 1.8, 2.0 3
row(7) 1, 1, 1, 1, 1, 1; 4
row(8) 150, 98.0, 25.0, 56.0, 5
row(9) 0.8, 0.8, 0.9, 10, 12, 15, 6
row(10) 2.6, 8.7, 8.9, 6.5, 7.9; 7
row(11) 160, 46.0, 67.0, 86.0, 8
row(12) 5.8, 9..0, 7.6, 23, 45, 67; 9

note:row(i) - for reference only and will not be included in the output
file.

There are :
1. two categories in the file: row1-row3 and row4-row11.
2. 3 types here: 100 (row1), 150(row2) and 160(row3).
3. the last column of each of the line refers to the row number that
print on the file.
4. 2nd column of row(1)- row(3) is the row number as in(3) relate to
its type in category 2.
Eg: 2nd column type 100 in row(1) =1, which is same as the last
column value as in row(4).
2nd column type 150 in row(2) =5, which is same as the last
column value as in row(8)

A. First I read the type 100 and write part of the info in row(1).
Then I need to jump to category 2 to continue writing the other info
relate to it (row(4) tp row(7)).

B. I jump back to row(2) working on type 150. From (A), I know that the
value I am going to print for the column2 is 5. Continue writing the
info, jump to category 2....

C. same as above.

I wonder how actually can I jump up and down writing all the info into
a file?

You could use seek functions, but that can get messy. I advise
simply reading the entire input file into an array, then you
can 'jump around' all you want by using an index into the array.
In what way I can do that? More importantly I do not how many lines I
need for each type in category 2.

You can find how many lines are in a file by reading through the
file and counting the '\n' characters.

IOW I'd tackle this roughly like:

1. Do a 'pre-read' of the entire file to count the lines.

2. Use the line count in your determination of how large
an array you'll need. (during this you can also determine
how many items are on each line, if that info is needed).

3. Rewind or close and reopen the file, and read it again,
this time storing your data in the array.

4. Access the items in your array in an order you like, by
specifying the appropriate array indices. Output the
desired information.


-Mike
 
J

jeff_zhang446

thanks. I think I did not explain clearly in the first message. The
example is the result of my output file.

I store my data in a link list.
list - type100
- type150
- type160

Say for type 100.
row(1) 100 1 t100.a t100.b t100.c t100.d t100.e t100.f 1
row(4) 100, t100.b[0], t100.b[1],t100.b[2], 1
row(5) t100.b[3],t100.b[4],t100.d[0],t100.d[1],t100.d[2],t100.d[3], 2
row(6) t100.d[4],t100.d[5],t100.d[6],t100.d[7],t100.d[8], 3
row(7) t100.k[0],t100.k[1],t100.k[2],t100.k[3],t100.k[4],t100.k[5]; 4

The last column at category 2 is fixed at column 60th. The data input
has to be between column 1 and column 55.

I wonder if I store each row of 'string' in an array with max size of
55 character?
array[0] = row1;
array[1] = row4;
array[2] = row5;
array[3] = row6;
array[4] = row7;
array[5] = row2;
array[6] = row8;
array[7] = row9;
array[8] = row10;
array[9] = row3;
..
..
..
If this is the case, would it be hard to keep track the row num in
catergory 2?

Please correct me if I am wrong.

thank you.

jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,183
Latest member
OrderGlycoEase

Latest Threads

Top