Computer Science Canada

Writing to a file without overwriting anything

Author:  ans4 [ Sun May 20, 2007 10:53 am ]
Post subject:  Writing to a file without overwriting anything

Is there a way that you can go to the end of a file and write something to there without erasing everything in the file?

Author:  DIIST [ Sun May 20, 2007 11:25 am ]
Post subject:  Re: Writing to a file without overwriting anything

Use mod in the open file command. Like shown here:
Turing:

var stream : int
var variable : string := ""
open : stream, "file.txt",get,put,mod

loop
    exit when eof (stream)
    get : stream, variable :*      %reads the line
end loop

%Now at the end of file, it writes some new line.
put:stream, "Some string at the end of the file"

close:file


I modified my the example i posted in you last thread! It would be the same for binary files except you replace put and get with write and read. Hope this was helpfull. Wink


: