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

Username:   Password: 
 RegisterRegister   
 How do u put stuff into a text file!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nate




PostPosted: Sun Jun 15, 2003 7:10 pm   Post subject: How do u put stuff into a text file!

Like you get a value and then you put that value into the file!
Sponsor
Sponsor
Sponsor
sponsor
hskhan




PostPosted: Sun Jun 15, 2003 7:24 pm   Post subject: (No subject)

code:
var stream : int
var line : string
%filename goes in place of inst.txt
open : stream, "inst.txt", put

% Write the file
loop

line:= "what ever"
    exit when eof (stream)
    put : stream, line : *


end loop
nate




PostPosted: Sun Jun 15, 2003 7:31 pm   Post subject: (No subject)

don't you have 2 close the file at the end!?
hskhan




PostPosted: Sun Jun 15, 2003 7:36 pm   Post subject: (No subject)

nate wrote:
don't you have 2 close the file at the end!?

wopdie do. Razz
code:

close : stream
naoki




PostPosted: Sun Jun 15, 2003 9:35 pm   Post subject: (No subject)

i'm too lazy to check if it errors, but i'm pretty sure you can't put to a file like that

going "put: stream, name : *" is wrong, you don't need the * when putting, only when you get a string
Martin




PostPosted: Sun Jun 15, 2003 9:43 pm   Post subject: (No subject)

Yeah, the above isn't goign to work at all. Here's how you do it.

code:
var fin : int
open : fin, "inputfile.txt", get
var x : int
var y : string
var z : string
get : fin, x %will read one integer
get : fin, y:* %will read an entire line
get : fin, z %will read one word.
close : fin


That's file input
suppose your file looked like this:
code:
1 2 3
hello world


x would have a value of 1 (the first integer, y would have a value of "2 3", and z would have a value of 'hello'

for file output, you do the following
code:
var fout : int
open : fout, "outputfile.txt", put
put : fout, "THIS IS NOW IN THE FILE"
put : fout, 1 + 2 + 3
close : fout


outputfile.txt now looks like this:
code:
THIS IS NOW IN THE FILE
6


Also, if outputfile.txt doesn't exist it will be created. If it does exist, opening it for put will delete it and replace it with a new blank file.
Hope that clears it up.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: