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

Username:   Password: 
 RegisterRegister   
 Adding onto datafile trouble
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shoobyman




PostPosted: Sat Nov 18, 2006 4:00 pm   Post subject: Adding onto datafile trouble

code:
var age : flexible array 1 .. 1 of int
var fname, lname : flexible array 1 .. 1 of string
var choice : string (1)
var stream : int

proc addDATA
    open : stream, "data7.t", seek, put
    seek : stream, *
    loop
        put "Please enter the last name: "
        get lname (upper (lname))
        put "Please enter the first name: "
        get fname (upper (fname))
        put "Please enter the age: "
        get age (upper (age))
        put : stream, lname (upper (lname)), " ", fname (upper (fname)), " ", age (upper (age))
        new lname, upper (lname) + 1
        new fname, upper (fname) + 1
        new age, upper (age) + 1
        put "Would you like to keep adding people to the list?"
        put "y/n"
        loop
            getch (choice)
            if choice = "n" or choice = "N" then
                put "Proceeding back to menu..."
                delay (400)
                exit
            elsif choice = "y" or choice = "Y" then
                exit
            else
                put "THAT IS NOT A CHOICE"
            end if
        end loop
        if choice = "n" or choice = "N" then
            exit
        end if
    end loop
    close : stream
end addDATA


addDATA

I am sure that this is really simple to fix, but everytime that it writes onto the datafile, it erases what was on it previously (if you run the program more than once). Can anyone tell me how to fix this?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Nov 18, 2006 9:15 pm   Post subject: (No subject)

Go to the [Turing Walkthrough]. Find the tutorial for files. Read it. It will explain that simply writing to the file will erase what is in it previously. You'll have to use mod to append stuff to the end of the file. And if you want to do some more fancy stuff, you'll want to look up tell and seek.
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: