Computer Science Canada Searching through a textfile. |
Author: | Anonymous [ Thu May 11, 2006 9:36 pm ] |
Post subject: | Searching through a textfile. |
This program is supposed to manage a video store, but I am having trouble with actually searching all of my .txt file and locating a specific entry I added and deleting it. It's located at line 150 in the REMOVE procedure. All I want to do is enter the movie title and delete that 1 entry. I still have over a month left and I'm almost done =) I'll probly expand on it graphically and more user friendly later on. |
Author: | Cervantes [ Tue May 16, 2006 5:28 pm ] | ||
Post subject: | |||
Haven't looked at the code, but wouldn't it be a matter of iterating through each line of your data file and comparing that line to the line you want to delete, and if it matches, you delete that line? As for how to delete that line, here's how I would recommend doing it, assuming the order of your data in your file does not matter. Continue iterating through the file until you reach the last line. Copy that line over top of the line you want to delete. You'll need seek and tell to move back to the line that you want to delete. Check the Turing Help manual for an explanation of what they do. The code might look like this, except you'd probably want to fix all my syntax errors:
Note that this will only work if all your lines are of uniform length. ie. there are the same number of bytes in each line. If not, you should pad each line with spaces so that it will be as large as the largest possible line. |