Computer Science Canada

calling info from text files

Author:  skier [ Fri Nov 12, 2004 3:56 pm ]
Post subject:  calling info from text files

does anyone no how to get arrays t save to a text file.i have got it to do single numbers but i cant get it to do arrays.
code:


var fileName : string := "filename.txt"
var file : int
var s : string
var num:int
num:= 5

open : file, fileName, put
put : file, num
close (file)

open : file, fileName, get
get : file, s : *
put s
close (file)


any help?

Author:  Tony [ Fri Nov 12, 2004 4:05 pm ]
Post subject: 

well just keep on writing to file and not close it...
code:

for i : 1 .. upper (my_array)
    put : file, my_array (i)
end for

Author:  skier [ Fri Nov 12, 2004 4:14 pm ]
Post subject: 

thats what i was doing before and it wasnt working but now it is. maybe i frogot to put in "upper".

how do i call all the info for an array.i tyed just calling th variable but it doesnt work.how do i do this ?

Author:  Mr. Glib [ Sun Nov 14, 2004 3:27 pm ]
Post subject:  Re: calling info from text files

skier wrote:
does anyone no how to get arrays t save to a text file.i have got it to do single numbers but i cant get it to do arrays.
code:

snip


any help?


With arrays, remember those pesky little index values.

var x : array 1..2 of int
x(1) :=10
x(2) :=3

open : stream, filename, put

for y : 1..2
put : stream, x(y)
end for


: