Computer Science Canada

searching and retriving specific information in a file.

Author:  TokenHerbz [ Tue Apr 25, 2006 6:19 pm ]
Post subject:  searching and retriving specific information in a file.

Hey, i was looking threw some tut's and didn't find anything to help me, and neither did that F10...

So i ask, can you read and write informaion in a spefic spot?

meaning:

i have a file: i want to add to it, line2, "this is a test", then again line 3" another test"

now i want to read just line 2, not line 1 or 3... and get my vars (strings)

Anyways, anything to help me would be pleasent...

Author:  TokenHerbz [ Tue Apr 25, 2006 6:23 pm ]
Post subject: 

I cant edit: I wanted to add this cause my previous post is a little hard to understand maybe,

i want to read and write by lines in the file

code:

line 1
line 2
line 3


each line should have 3 vars in my program..

I want to beable to access only certain lines when needed, be able to add more, and delete them. Sorry for that post Sad no edit tho.

Author:  Cervantes [ Tue Apr 25, 2006 6:27 pm ]
Post subject: 

You can use seek and tell in tandem to move to different parts of your file. However, even with these tools you cannot jump directly to a given line (unless you know how many bytes in a given line is).

You can cycle through lines, storing them in a temp variable, until you get the desired line.

As for adding more, you just have to open the file with the mod option.

code:
open : file_stream, get, put, mod

I think that's the syntax.

Author:  MysticVegeta [ Tue Apr 25, 2006 6:40 pm ]
Post subject: 

Cervantes wrote:
I think that's the syntax.

not really

Author:  TokenHerbz [ Tue Apr 25, 2006 7:27 pm ]
Post subject: 

that says: "I think that's the syntax." (for people with bad eyes)


well i will try with these tools, any other info would be nice.

Author:  TokenHerbz [ Tue Apr 25, 2006 7:45 pm ]
Post subject: 

EDIT:

Cervantes wrote:
[code]
(unless you know how many bytes in a given line is).
[code]

Can i check how many letters and spaces there are up to the givin line and use that info to determin where to start reading?

[code]
var1 var2 var3
var4 var5 var6
var7 var8 var7
%%all differnent length strings Razz
[/code]

even if i found away to start reading at var 4, how do i only read var4, var5, var6??? and leave everything else there.

Author:  Cervantes [ Tue Apr 25, 2006 8:14 pm ]
Post subject: 

Sorry, forgot the filename.
code:

var file_no : int
open : file_no, "foo.txt", put, get, mod


TokenHerbz: If you're at line 2 (var4), then just read the whole line to get var4, var5, and var6. You can use : * to get the whole line then break it up yourself, or you can omit the : * to get data separated by spaces.

If you don't want to read the vars after var6, you just don't read/get them.

Author:  MysticVegeta [ Wed Apr 26, 2006 1:39 pm ]
Post subject: 

TokenHerbz wrote:
that says: "I think that's the syntax." (for people with bad eyes)


you know you could just copy it and paste it anywhere else to see what that means right?


: