Possible to have an array of String arrays? (solved)

I know using Strings is bad practice, but I'm using them for this quickie project, and I'd like to have each item in the array of Strings be an array of Strings. But I can't figure out the syntax.

Something like:

String hair_color[2] = { ["marty", "brown"], ["wendy", "red"], };

Does anyone happen to know how to do this?

uno
dos
tres
quatro
cinco

alpha
bravo
charlie
delta
echo
#define N 5
String  ids [][N] = {
    { "uno", "dos", "tres", "quatro", "cinco" },
    { "alpha", "bravo", "charlie", "delta", "echo" }
};

// -----------------------------------------------------------------------------
void list (
    int set)
{
    for (unsigned n = 0; n < N; n++)
        Serial.println (ids [set][n]);
    Serial.println ();
};

// -----------------------------------------------------------------------------
void setup ()
{
    Serial.begin (9600);

    list (0);
    list (1);
}

// -----------------------------------------------------------------------------
void loop () {
}
1 Like

Thank you! I banged my head against the wall for an embarassingly long time on that. Was missing the second set of square brackets in the declaration.

i had already banged head against wall

1 Like

Of course having const char* instead of String instances would not hurt :wink:

1 Like

i agree; explain why

It Takes less memory you could even have them only in flash memory

String hair_color[][2] = 
{ 
  {"marty", "brown"}, 
  {"wendy", "red"}, 
};

const size_t hair_color_count = sizeof hair_color / sizeof hair_color[0];

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.