Multi dimensional array ???

Posted By: spaceguy76

Multi dimensional array ??? - 09/28/09 23:05

What is the correct way to set up a multi dimensional
array in C-lite? In Java it is:

int grad3[][] = {{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0},
{1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1},
{0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}};

But that is a syntax error to plug it in that way. Anyone care to enlighten me? Please? tongue
Posted By: SomebodyNew

Re: Multi dimensional array ??? - 09/29/09 07:35

I'm not sure whether you mean C-script or lite-C, but as far is I know you can't define a multidimensional array in its declaration line.

That is pretty annoying, I know.

Here is a workaround though:

1.)If you want your array to consist only of zeros -> use a loop.

2.)If you want to fill it with numbers:
Declare a ONEdimensional array and insert all the numbers you need (for example hello[100]). Then use a function that fills in the first 10 numbers in your multidimensional array's first line, the next ten in its second line and so on.

Here is the link, both methods are explained:
http://www.opserver.de/ubb7/ubbthreads.p...true#Post277469
Posted By: MrGuest

Re: Multi dimensional array ??? - 09/29/09 23:31

yeah, unfortunately not possible to predefine multi-dimesional arrays

though you could init a _startup function to do it all for you?

or you could just multiply with width*height and preset it all? = { x, x;}
Posted By: spaceguy76

Re: Multi dimensional array ??? - 09/30/09 23:57

I paged through the manual a bit more and found out multidimensional arrays aren't kosher. I figured out the work around but wasn't happy with the code I was working with so I scrapped it and started over again. Thanks for the responses.
Posted By: Alan

Re: Multi dimensional array ??? - 10/01/09 10:23

How about using a matrix? As far as I know, Matrices and multidimensional Arrays are about the same. Never used them, though, but you could check the manual on that.

Greets,


Alan
© 2024 lite-C Forums