
-----------------------------------
chrisbrown
Sat Feb 18, 2006 5:47 pm

Passing arrays
-----------------------------------
I don't know if this has been addressed in this forum; I gave up serching through the 63 pages of hits the search term "passing arrays" returned. Anyways, I'm writing a football game and I need to pass a 2D array to a procedure which will then write the contents of that array to a file. The I/O is no problem for me, but if anyone knows how to pass arrays please let me know. 
Thanks

-----------------------------------
Cervantes
Sat Feb 18, 2006 6:01 pm


-----------------------------------
Welcome to CompSci.ca! :)

You can pass an array into a procedure, like this:

proc test (arr : array 1 .. 10 of int)

Of course, what if the array doesn't end at 10?

proc test (arr : array 1 .. * of int)

This will accept an array with a lower bounds of 1 and an upper bounds of mostly anything.

A 2D array can be done like this:

proc test (arr : array 1 .. *, 1 .. * of int)


Here's an example:

proc test (arr : array 1 .. *, 1 .. * of int)
    put arr (1, 1)
end test

var my_arr : array 1 .. 5, 1 .. 3 of int
my_arr (1, 1) := 42

test (arr)


-----------------------------------
Delos
Sat Feb 18, 2006 11:00 pm


-----------------------------------
Or do you mean parse?  That would entail an analysis of each element and redistribution based upon their inherent structures as per your afore setup grammatical structure...:D
Or something like that.  Listen to Cervantes.
