How to initialize three-dimensional array in Arduino? -


I just build my fist LED cube and want to expand the test code a little bit. To address each LED address of my 3x3x3 cube, I want to use a related three-dimensional array, but I get errors in its initialization.

Here I have done that:

  int Cube_matrix [3] [3] [3] = {{{0}, {0}, {0}}, {{0}, {0}, {{}}, {{0}, {0}, {{}}}, {{{0}, {0}, {0}}, {{0}, { {}, {0}, {0}, {0}, {0}}}, {{0}, {0}, {0}}, {{0}, {0}, {0} }, {{0}, {0}, {0}}}; Here is an error that I get:  

Error: Expected Unqualified-ID '{' before the token P> I can use the loop to start my array and can complete things, but my initial form seems right for me, and I want to know what I did.

If you are really targeting to allocate the whole thing with zero, then you You can use a simplified starter:

  int cube_matrix [3] [3] [3] = {0};  

If you want more than zero, you can also do this:

  #include & lt; Stdio.h & gt; Int main (int argc, char * argv []) {int cube_matrix [3] [3] [3] = {1, 2, 3, 4, 5}; Int i, j, k; For (i = 0; i & lt; 3; i ++) for (j = 0; j & lt; 3; j ++) for (k = 0; k & lt; 3; k ++ ) Printf ("% i% i% i:% i \ n", I, J, Q, Cubmatics [i] [J] [K]); Return 0; }  

Output that looks like this:

$ ./a.out 0 0 0: 1 0 0 1: 2 0 2 2: 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1: 0 1 1 2: 0 1 2 0: 0 1 2 1: 0 1 2 2: 0 2 0 0: 0 2 0 1: 0 2 0 2: 0 2 1 0: 0 2 1 1: 0 2 1 2: 0 2 2 0: 0 2 2 1: 2 2 2: 0

Comments