Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Save data to a txt file without deleting existing content??
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ashan




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Fri Mar 26, 2004 9:27 pm   Post subject: (No 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.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
ashan




PostPosted: Sat Mar 27, 2004 10:11 am   Post subject: (No 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
recneps




PostPosted: Sat Mar 27, 2004 10:25 am   Post subject: (No 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
sport




PostPosted: Sat Mar 27, 2004 7:01 pm   Post subject: (No subject)

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




PostPosted: Sun Mar 28, 2004 11:01 pm   Post subject: (No subject)

thanks guys,

it really helps, you guys are amazing


keep up the good work Laughing


thanks & REgds

Ashan
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: