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

Username:   Password: 
 RegisterRegister   
 Searching through a textfile.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Guest




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




PostPosted: Tue May 16, 2006 5:28 pm   Post subject: (No 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:
code:

proc delete_line (line : string, file_stream : int)
    var pos : int
    var current_line : string
    loop
        exit when eof (file_stream)
        get : file_stream, current_line
        if current_line = line then
            tell : file_stream, pos % I really don't remember the syntax for this one; sorry
        end if
    end loop
    % current_line is now the last line in the file
    seek : file_stream, pos
    put : file_stream, current_line
end delete_line

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.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: