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

Username:   Password: 
 RegisterRegister   
 Saving a 2D arry to a file.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jonny Tight Lips




PostPosted: Mon Sep 06, 2004 4:25 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Mon Sep 06, 2004 6:26 pm   Post subject: (No subject)

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:

code:

%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.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Jonny Tight Lips




PostPosted: Tue Sep 07, 2004 3:57 pm   Post subject: (No subject)

Oh Got it. Thanx a lot Dan!!! Very Happy Very Happy I am not worthy I am not worthy

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




PostPosted: Tue Sep 07, 2004 5:30 pm   Post subject: (No subject)

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.

code:

%outputing to the screen
for i:1..x
   for ii:1..y
         put myarray (i,ii) ..
         put " " ..
  end for
   put ""
end for
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
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  [ 4 Posts ]
Jump to:   


Style:  
Search: