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

Username:   Password: 
 RegisterRegister   
 Im confused on how to output data to a txt file.....
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
INFERNO2K




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jun 09, 2003 6:06 pm   Post subject: (No subject)

read tutorial on writing to files.

if you're opening for put/get you use put get, NOT write/read
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
INFERNO2K




PostPosted: Mon Jun 09, 2003 6:10 pm   Post subject: (No subject)

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




PostPosted: Mon Jun 09, 2003 6:25 pm   Post subject: (No 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.
PaddyLong




PostPosted: Mon Jun 09, 2003 7:15 pm   Post subject: (No 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
Andy




PostPosted: Mon Jun 09, 2003 7:18 pm   Post subject: (No subject)

close the file at the end
close (file)
PaddyLong




PostPosted: Mon Jun 09, 2003 7:37 pm   Post subject: (No subject)

that too Razz
Homer_simpson




PostPosted: Mon Jun 09, 2003 9:05 pm   Post subject: (No 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
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  [ 8 Posts ]
Jump to:   


Style:  
Search: