Computer Science Canada

Im confused on how to output data to a txt file.....

Author:  INFERNO2K [ Mon Jun 09, 2003 6:04 pm ]
Post subject:  Im confused on how to output data to a txt file.....

I have a game and I want to output the players name and his score next to his name

code:
var stremin :int %a var that is an int is needed to open a file
var stremout :int %a var that is an int is needed to open a file

open: stremout, "Highscores.txt", put %this will open a connection to send data


write : name1, " - ", score1
write : name2, " - ", score2
close: stremout


I tried this but it doesnt work.

Also how would I be able to keep this txt file and everytime I run this program it will add a new line instead of replacing the existing information?

Thanks

Author:  Tony [ Mon Jun 09, 2003 6:06 pm ]
Post subject: 

read tutorial on writing to files.

if you're opening for put/get you use put get, NOT write/read

Author:  INFERNO2K [ Mon Jun 09, 2003 6:10 pm ]
Post subject: 

I've tried and all I get is a Cent symbol, C with a dash through it in the text file.

Author:  INFERNO2K [ Mon Jun 09, 2003 6:25 pm ]
Post subject: 

Ok I simply used
code:
var streamOut : int
open : streamOut, "Highscores.txt", put
put : streamOut, name1, "  -  ", score1
put : streamOut, name2, "  -  ", score2


Now Im confused on how I can keep that file and the program uses it to add onto it instead of replacing the original text.

Author:  PaddyLong [ Mon Jun 09, 2003 7:15 pm ]
Post subject: 

open it with mod and seek as well

you really should read the help file for open and read the things listed under "see also" because it lists all the parameters (just type open in your editor, put the cursor on it and press f9 or just open the help and search for open)

any way for your purposes I believe this is what you want...
code:

var streamOut : int
open : streamOut, "Highscores.txt", put, mod, seek
seek : streamOut, *  %goes to the end of the file...
put : streamOut, name1, "  -  ", score1
put : streamOut, name2, "  -  ", score2

Author:  Andy [ Mon Jun 09, 2003 7:18 pm ]
Post subject: 

close the file at the end
close (file)

Author:  PaddyLong [ Mon Jun 09, 2003 7:37 pm ]
Post subject: 

that too Razz

Author:  Homer_simpson [ Mon Jun 09, 2003 9:05 pm ]
Post subject: 

this code simply reads and prints text.txt
code:
var fileName : string := "text.txt"           % Name of file
var fileNo : int                        % Number of file
var ch : char
open : fileNo, fileName, get

loop
    exit when eof (fileNo)
    get : fileNo, ch
    put ch ..
end loop


: