Computer Science Canada

Save data to a txt file without deleting existing content??

Author:  ashan [ Fri Mar 26, 2004 9:12 pm ]
Post subject:  Save data to a txt file without deleting existing content??

Hey guys,

I' m creating licence plate database and I want to reserve the licence plates that are already being purchased. So I added an extra charcter (*) to the end of the licence plate # (eg: 123-ABC*).

But the problem is how can I replace this licence plate # (123-ABC*) to the existing licence plate # (123-ABC) without deleting the entire database (in the txt file). I know that you can't use "put:..." because it delete the whole file before the data get saved.

So can someone pls tell me how to save data to a txt file without deleting existing content?? Laughing

Thanks & Regds,

Ashan

Turing beginner Sad

Author:  Dan [ Fri Mar 26, 2004 9:27 pm ]
Post subject: 

well load the hole data base in to an array.

then go throw it make the chages

and then wirte the contents of the array over the old db file.

just make shure to move the data up one if u delte an entry in the array so you dont get any erros or unwhonted spaces when u write to the file.

Author:  ashan [ Sat Mar 27, 2004 10:11 am ]
Post subject: 

i'M SORRY,
but I can't understand what are you trying to say. Cuz if I put a array then it will write the whole file again (clear everything).

could you pls show me how to do it.!


Thanks & REgds

Ashan

Author:  recneps [ Sat Mar 27, 2004 10:25 am ]
Post subject: 

he means kinda like this...
code:
var y,stream,data:int
open:stream,"filename",get
loop
get:stream,data
exit when eof(stream)
y+=1%this loop gives you the max value for your array (theres probably easier way but i do it this way)
end loop
close:stream
var file:array 1..y of string
open:stream,"filename",get
for i:1..y
get: stream,file(i)
end for
close:stream
%edit the array pieces...
open:stream,put
for i:1..y
put:stream,file(i)
end for

Hes not saying to edit a file without erasing, hes saying you have to load it all into the memory, then edit it, and then put it back in file. The only way you can do that (that i know of) is in VB Wink

Author:  sport [ Sat Mar 27, 2004 7:01 pm ]
Post subject: 

In grade 11 they teach binary files and records and that is the easiest way to modify files.

Author:  ashan [ Sun Mar 28, 2004 11:01 pm ]
Post subject: 

thanks guys,

it really helps, you guys are amazing


keep up the good work Laughing


thanks & REgds

Ashan


: