PDA

View Full Version : How to initialize multidimensional arrays in C



happy_99
08-03-2005, 01:02 AM
Hi All,

I'm having problems with the following code.


int tripod1[5][5][3]=
{
{0,1,2},{10,11,12},{20,21,22},{30,31,32},{40,41,42 },

{100,101,102},{110,111,112},{120,121,122},{130,131 ,132},{140,141,142},

{200,201,202},{210,211,212},{220,221,222},{230,231 ,232},{240,241,242},

{300,301,302},{310,311,312},{320,321,322},{330,331 ,332},{340,341,342},

{400,401,402},{410,411,412},{420,421,422},{430,431 ,432},{440,441,442}
};

I'm getting the error "Too many initializers". Pls tell me what to do.

Thanks and Regards

happy_99

cheenu
08-03-2005, 05:34 AM
Hey happy,
Ur program has syntax error.
It should be something like this:
int tripod1[5][5][3]=
{
{{0,1,2},{10,11,12},{20,21,22},{30,31,32},{40,41,4 2}},

{{100,101,102},{110,111,112},{120,121,122},{130,13 1,132},{140,141,142}},

{{200,201,202},{210,211,212},{220,221,222},{230,23 1,232},{240,241,242}},

{{300,301,302},{310,311,312},{320,321,322},{330,33 1,332},{340,341,342}},

{{400,401,402},{410,411,412},{420,421,422},{430,43 1,432},{440,441,442}}
};

Note that each dimension has to be enclosed within flower braces.
Hope this helps.
With warm Regds,
Cheenu.

happy_99
08-04-2005, 12:23 AM
Cheene, u helped me a lot man. Thanks a ton for that !!

Regds

happy_99