473,586 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to write these info to file?

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

Nov 15 '05 #1
2 1390
<je***********@ yahoo.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
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
Nov 15 '05 #2
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

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3303
by: Viviana Vc | last post by:
How can I programatically do the equivalent of the following: cacls "C:\Program Files\test" /T /G Everyone:f ? Thanks, Viv
2
2072
by: jeff_zhang446 | last post by:
Hi, I try to write some data structure into a file as below and would appreciate if someone can give me some advice here. The output file looks like below: 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
3
15698
by: Mads Westen | last post by:
Hi, I'm making some changes to my program, because I need to write with Codepage 850. Before I used FileStream, but I found code to use with StreamWriter instead. My problem is, that I don't get any output when writing with StreamWriter, but only with FileStream. I got StreamWriter to work in another class, where I only have 1 Writeline
3
3441
by: Pitmairen | last post by:
I want to make a program that get info from a website and prints it out in a txt file. I made this: import urllib f = urllib.urlopen("http://www.imdb.com/title/tt0407304/") s = f.read() k = open("test.txt","w") k.write(s)
0
789
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
14046
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
16
4673
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good) free hoster in Norway which doesn't use safe mode, running PHP 5.1.6 as the PHP info below shows ... Test it at:...
1
3752
by: banging | last post by:
Hi there, I have a question regarding locking of tables so that when two or more people try to write or update the mysql tables, it locks up. Basically I only want one person to write to the file, but many are able to read the files (or tables entities). I am not sure if I need to lock the tables in my Java code or do I lock the tables...
6
14543
by: A.Rocha | last post by:
Hi, I need save to text file a List<type>, but i dont wont serialize. // List<mytypemyList = new List<mytype>(); anyone can help me? --
0
7841
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8204
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7965
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3838
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1184
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.