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

Username:   Password: 
 RegisterRegister   
 [Tutorial] How to read and write to a file in Turing
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
unknowngiver




PostPosted: Fri May 19, 2006 4:08 pm   Post subject: (No subject)

hey
what if i want to write to a file without overwriting the current stuff...and also wt if iwant to overwrite SOME of the file but not all

for example

lets say on my program where users can change the OPTIONS of the game..

the OPTIONS are saved in a file called options.txt

so it may look like
options.txt:
code:

skin = "redmonster"
language = "english"
background_music = "bg.mid"
bg_image = "bg.jpg"

and the user goes to the options and changes ONLY the skin to something else..let say "blue"
how would i make it so thts the only thing tht changes??
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri May 19, 2006 5:29 pm   Post subject: (No subject)

You'd probably cycle through your data file until you reach the line that defines the skin colour, then overwrite it with the new line.

Note, however that that line has a certain number of bytes (one byte per character). You cannot change the number of bytes that line has (since that would screw up following lines). Thus, you must make sure the line you are inserting is less than or equal to the current line. If the replacement line is shorter, pad it with spaces.

You will need to use the mod option when opening the file:
code:

open : file_stream, "filename.txt", put, mod
seawad_




PostPosted: Wed Nov 05, 2014 4:16 pm   Post subject: Re: [Tutorial] How to read and write to a file in Turing

When I try to do:

put : file, "Hi, I like to eat hamburgers"

Turing says:

Put attempted on incompatible stream number 1.

Please help.
I would like to know how to fix this problem.
Tony




PostPosted: Wed Nov 05, 2014 4:35 pm   Post subject: RE:[Tutorial] How to read and write to a file in Turing

how are you initializing your file variable?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ylcc23




PostPosted: Tue Jan 13, 2015 9:02 am   Post subject: RE:[Tutorial] How to read and write to a file in Turing

When ever I try to open the .txt file I need for my program, I get syntax error at 'end'. Expected '.' I'm not sure what is causing the syntax error, as I used the code from this tutorial. Error occurs at end loop. I think it has something to do with the colon in my get, but I'm not entirely sure.

Turing:

proc instructions
    var file : int
    open : file, "checkers instructions.txt", put, mod
    loop
        exit when eof (file)
        get : file
    end loop
end instructions
Insectoid




PostPosted: Tue Jan 13, 2015 10:15 am   Post subject: RE:[Tutorial] How to read and write to a file in Turing

your get instruction is missing something.
ylcc23




PostPosted: Wed Jan 14, 2015 2:19 pm   Post subject: RE:[Tutorial] How to read and write to a file in Turing

I've tried a different way of reading the file, but it returns a blank screen. Not sure why it won't work.

Turing:

proc instructions
    open : file, "checkers instructions.txt", get
    assert file > 0
    for i : 1 .. 2
        exit when eof (file)
        get : file, list (i)
    end for
    close : file
end instructions
Insectoid




PostPosted: Wed Jan 14, 2015 2:57 pm   Post subject: RE:[Tutorial] How to read and write to a file in Turing

Well that code doesn't output anything, so there's nothing to write to the screen.
Sponsor
Sponsor
Sponsor
sponsor
ylcc23




PostPosted: Thu Jan 15, 2015 8:59 am   Post subject: RE:[Tutorial] How to read and write to a file in Turing

I've added in a put statement but all that does is print 2 in the top left corner of my screen. Any advice?

Turing:

proc instructions
    open : file, "checkers instructions.txt", get
    assert file > 0
    for i : 1 .. 2
        exit when eof (file)
        get : file, list (i)
    end for
    put file
    close : file
end instructions
Insectoid




PostPosted: Thu Jan 15, 2015 10:23 am   Post subject: RE:[Tutorial] How to read and write to a file in Turing

Putting a file will not output the contents of that file. You need to put the variables that you stored the contents of file in.
Raknarg




PostPosted: Thu Jan 15, 2015 8:08 pm   Post subject: RE:[Tutorial] How to read and write to a file in Turing

As a side note, you are getting 2 because 'file' is an integer, and all it stores is a streamID
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 26 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: