Author |
Message |
JayLo
|
Posted: Tue Apr 15, 2003 5:02 pm Post subject: Initializing a two/three dimensional array. |
|
|
how do you initialize values for a two dimensional array?
I know that arrays would be:
var x : array 1 .. 3 of int := init (3,5,7)
but what about 2d arrays? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Blade
|
Posted: Tue Apr 15, 2003 5:15 pm Post subject: (No subject) |
|
|
heres the example from help
Quote: Example
var mensNames : array 1 .. 3 of string :=
init ( "Tom", "Dick", "Harry" )
put mensNames ( 2 ) % This outputs Dick
var names : array 1 .. 2, 1 .. 3 of string :=
init ( "Tom", "Dick", "Harry",
"Alice", "Barbara", "Cathy")
put names ( 2, 1 ) % This outputs Alice
it should explain it for you |
|
|
|
|
|
Tony
|
Posted: Tue Apr 15, 2003 5:19 pm Post subject: (No subject) |
|
|
once again, read the tutorial on the arrays. It covers EVERYTHING you need to know, including explanation of multidimentional arrays. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Blade
|
Posted: Tue Apr 15, 2003 5:34 pm Post subject: (No subject) |
|
|
i read it and it didnt tell me how to initilize 2d arrays... |
|
|
|
|
|
Tony
|
Posted: Tue Apr 15, 2003 5:53 pm Post subject: (No subject) |
|
|
read the tutorial again
Quote: Some array tricks - 2D arrays
Here's something that I used to scare people with right before grade10 compsci exam... "you need to know 2D arrays". People were freaking out... I donno why
Anyway, the point is that each of our little "boxes" in an array can contain a row of boxes of its own. So for each box in a row, we get another row, forming columns. This way we just created a grid (also called matrix).
it's decleared as
Code:
var grid:array 1..10, 1..5 of int
10 rows, 5 columns. Though that depends how you look at it and how you set up your forloops. I had a huge argument with my teacher of what value gous first - row or column. I dont remember what she said, but in my opinion it doesnt matter - as long as you know
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Catalyst
|
Posted: Tue Apr 15, 2003 6:07 pm Post subject: (No subject) |
|
|
i think he means using the init command... |
|
|
|
|
|
Tony
|
Posted: Tue Apr 15, 2003 6:53 pm Post subject: (No subject) |
|
|
ah crap.
Blade is right then.
though why initialize arrays? just get info from a file |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Blade
|
Posted: Tue Apr 15, 2003 9:21 pm Post subject: (No subject) |
|
|
YAY BLADE IS RIGHT!! go blade go, oh yeah uh huh! hehe i wouldnt have argued with you if i didnt know i was right tony |
|
|
|
|
|
Sponsor Sponsor
|
|
|
JayLo
|
Posted: Wed May 07, 2003 6:16 pm Post subject: (No subject) |
|
|
about initializing from a text file...
how? |
|
|
|
|
|
Tony
|
Posted: Wed May 07, 2003 6:43 pm Post subject: (No subject) |
|
|
:= init(variable1, variable2, ... , variableN)
or just read from the file and save values right in the array |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Homer_simpson
|
Posted: Wed May 07, 2003 7:11 pm Post subject: (No subject) |
|
|
my new tetris project uses 2d arrays that might help u if u take a look at it.... |
|
|
|
|
|
|