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?
gcjr
March 11, 2022, 6:17pm
2
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.
gcjr
March 11, 2022, 6:40pm
4
i had already banged head against wall
1 Like
J-M-L
March 11, 2022, 6:46pm
5
Of course having const char* instead of String instances would not hurt
1 Like
J-M-L
March 12, 2022, 6:36am
7
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];
system
Closed
September 8, 2022, 2:32pm
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.