Page 1 of 1

Array problem.

PostPosted: Sat Oct 03, 2009 1:17 pm
by equinox
Hi at ALL.

GLOBAL CODE:
int N[15] = {{2 3 4},{2 6 11}};

draw:

textnumber = N[0]; -> 2 3 4
textnumber = N[1]; -> 2 6 11
.....

not work. Why?

Tnk1000.

Re: Array problem.

PostPosted: Sat Oct 03, 2009 2:12 pm
by DST
are you trying to store 2, 3, and 4 in that array slot, or the number 234? You can't store separate numbers in one slot, you have to use a multidimensional array

N[15][3]

for instance.

then

N[0][0] will equal 2, and N[0][1] will be 3, etc.....

because SPACE is not an integer symbol.

Re: Array problem.

PostPosted: Sat Oct 03, 2009 2:25 pm
by Fuzzy
equinox wrote:Hi at ALL.

GLOBAL CODE:
int N[15] = {{2 3 4},{2 6 11}};


This is not a proper array. you have to fill in all 15 places and all numbers need to be separated with comma.

Code: Select all
int N[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

and it is one dimensional.

Code: Select all
int N[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}};


Is correct. All places must be initialized with a number. And they must follow the structure of the array.

draw:

textnumber = N[0]; -> 2 3 4
textnumber = N[1]; -> 2 6 11
.....

not work. Why?


N[0] can only store one number. 2, 3, 4 for example or 234. No spaces as DST said.

Re: Array problem.

PostPosted: Sat Oct 03, 2009 5:53 pm
by pyrometal
Fuzzy wrote:you have to fill in all 15 places and all numbers need to be separated with comma.


Not all spaces need to be filled upon initialization, but it is recommended practice since (if inside a function), the slots that are left undefined will have random values, or if this is a global variable then everything that is undeclared is initiated to zero (most c compilers do this). Sorry Fuzzy, I felt like clarifying these few points!