
-----------------------------------
Jonny Tight Lips
Mon Sep 06, 2004 4:25 pm

Saving a 2D arry to a file.
-----------------------------------
I was reading the tut on wrighting to files and it wasn't all that clear to me. Well I was wondering if there was an easyer way to make a 2D arry into a file.  Do I need a pre existing file to save. I've used SaveScreen and that makes a file for you. So a lil sample code would be nice if you can. Thanx a lot. Aslo what type of file will it be saved as? Ans what type of file can turing read?
The error I'm gettin says:
Write Attempted on incompadible stream number 1

-----------------------------------
Dan
Mon Sep 06, 2004 6:26 pm


-----------------------------------
Do u mean the pic from the screen your are trying to save or the data in the array?

If whont data then u use a nested for loop like so:


%the size of the arrays
var x:int := 10
var y:int := 10

%the array
var myarray : array 1..x, 1..y of int

%puting some data in the array
for a: 1..x
   for b:1..y
      myarray (a,b) := b
   end for
end for

%outputing to the screen
for i:1..x
   for ii:1..y
         put myarray (i,ii)..
   end for
   put ""
end for


Now this only outputs to the screen but you could easly chage it with file streams to out put to the file. Just add the file stuff from my tutoral to the put lines and add the stream vars.

-----------------------------------
Jonny Tight Lips
Tue Sep 07, 2004 3:57 pm


-----------------------------------
Oh Got it. Thanx a lot Dan!!!  :D  :D  :notworthy:  :notworthy:

But I have one last question. When I output the numbers to a file there all in on straight colum going down. I want then to be in a nice grid like formation with like 20 in a collum. Who would I do that?

-----------------------------------
Dan
Tue Sep 07, 2004 5:30 pm


-----------------------------------
see the .. after the put in my example? thats what dose that. do u have it in your code b/c it works in mine. If u put a .. after a put it should make the next put be on the same line. Tho you probly whont to add a space in there so they are not all touching on that line.


%outputing to the screen
for i:1..x
   for ii:1..y
         put myarray (i,ii) ..
         put " " .. 
  end for
   put ""
end for 

