Author |
Message |
unknowngiver
|
Posted: 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
|
|
|
Cervantes
|
Posted: 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_
|
Posted: 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
|
Posted: 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? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
ylcc23
|
Posted: 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
|
Posted: 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
|
Posted: 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
|
Posted: 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
|
|
|
ylcc23
|
Posted: 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
|
Posted: 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
|
Posted: 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 |
|
|
|
|
|
|