
-----------------------------------
nate
Sun Jun 15, 2003 7:10 pm

How do u put stuff into a text file!
-----------------------------------
Like you get a value and then you put that value into the file!

-----------------------------------
hskhan
Sun Jun 15, 2003 7:24 pm


-----------------------------------
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
Sun Jun 15, 2003 7:31 pm


-----------------------------------
don't you have 2 close the file at the end!?

-----------------------------------
hskhan
Sun Jun 15, 2003 7:36 pm


-----------------------------------
don't you have 2 close the file at the end!?
wopdie do. :P

close : stream


-----------------------------------
naoki
Sun Jun 15, 2003 9:35 pm


-----------------------------------
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
Sun Jun 15, 2003 9:43 pm


-----------------------------------
Yeah, the above isn't goign to work at all. Here's how you do it.

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:
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
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:
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.
