3 dimensional array?

While writing some code for a fellow forum member I came across an interesting problem. Is it possible to make a two dimensional array of character strings (effectively a 3d array)? It seems like it should be possible but I don't know and I'm not with my arduino to try it.

Heres what I think it should look like

char* tricks[][] = {
            {"first", "second", "third", "fourth", "fifth", "sixth", "seventh"},
            {"first", "second", "third", "fourth", "fifth", "sixth", "seventh"},
            {"first", "second", "third", "fourth", "fifth", "sixth", "seventh"},  
            {"first", "second", "third", "fourth", "fifth", "sixth", "seventh"}
          };

The reason I want to do it like this is so that I can do a for loop and call a random string from each group (basically)

You must provide the size out of the rows at least. Or better provide both sizes for row and column. Note that three dimensions can take quite some memory space.

Yeah I tried to compile it and it said I had to tell it how big it was, which I usually do I just forgot. I changed it to char* tricks[4][6] and it gave me the below error, which leads me to believe that its impossible. As for the space I know, but thats pretty much the only thing that requires large amounts of space so I think its safe.

error: too many initializers for 'char* [6]'

I wrote the code a different way but it would be much more elegant to use an array like this one if possible. See this thread:

http://arduino.cc/forum/index.php/topic,70173.0.html

This is why I was wondering...

I changed it to char* tricks[4][6] and it gave me the below error, which leads me to believe that its impossible.

Well yes, putting seven initialisers into a six element array is impossible.
Did you mean "char* tricks [4][7] = " ?

Wow now I feel dumb haha. I neglected to check how many elements there were when I wrote it...

int cube_matrix[3][3][3] = {

{{0,1,2},// row 0
{3,4,5},
{6,7,8}},

{ {9,10,11},
{12,13,14},
{15,16,17}},

{{18,19,20},
{21,22,23},
{24,25,26}}

};

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
for(int k=0;k<3;k++){

Serial.println(cube_matrix*[j][k]);*

  • delay(1000);*
    }
    }
    }
    }

Just supply the column count. Let the compiler count the rows for you

const uint8_t numColumns = 7;

const char * const tricks[][numColumns] = {
  {"first", "second", "third", "fourth", "fifth", "sixth", "seventh"},
  {"first", "second", "third", "fourth", "fifth", "sixth", "seventh"},
  {"first", "second", "third", "fourth", "fifth", "sixth", "seventh"},
  {"first", "second", "third", "fourth", "fifth", "sixth", "seventh"},
};

const uint8_t numRows = sizeof(tricks) / sizeof(tricks[0]);

@gfvalvo

You're replying to a nearly 8 year old post :wink:

I think this is the second thread @Gilberto_Gozzi revived. I'm not even sure if this is a question or a solution.

Yea, just noticed that.