Computer Science Canada Read and writing to a binary file |
Author: | timmytheturtle [ Sun Sep 19, 2004 7:54 pm ] | ||
Post subject: | Read and writing to a binary file | ||
What I need help with is im tryin to add names to a binary file using the read and write commands, I can get the name to write but it overwrites the first name in the file, How do I make it write the new name to the end of the list of names? Any help would be greatly appericated, thanks in advance part of the code:
|
Author: | Delos [ Mon Sep 20, 2004 10:41 am ] |
Post subject: | |
Hmm...I'm not all to familiar w/ read/write (being a get:/put: person myself) but I think your problem lies in the fact that you're writing directly to the file. Try to load the entire file into memory at one time, then get your changes, then edit them in memory, and then write them back into your file (clearing everything inside it first). I'm not sure if this defeats your initial purpose or not though...but it does work. |
Author: | Tony [ Mon Sep 20, 2004 1:14 pm ] |
Post subject: | |
no delos ![]() the point of random access is just that - access the file randomly ![]() if you want to write to the end of the file, you open it for :write, seek, mod and use seek:* to move to the end of the file. You can add new data there. somebody confirm if this is right or now, I personally never used random access with turing |
Author: | timmytheturtle [ Mon Sep 20, 2004 2:22 pm ] |
Post subject: | |
thanks for all your help, I hope it works. |
Author: | timmytheturtle [ Mon Sep 20, 2004 2:40 pm ] |
Post subject: | |
I just tried it and no luck, it overwrites the first name, but if i put 5(number of names originally in file) it puts the new name with the first name and puts a bunch of characters in fron of the name in the second line. Edit: I got it to work, I did need to seek to the end of the file |