in my code, I was using string class to make an array to store my menu items
String menu[2] = {{"Menu 1"}, {"Menu2"}};
How do I convert this into char arrays and how do I call them?
Example:
Serial.println(menu[0]);
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityCreate them as char arrays like this:
const char* menu[2] = {"Menu 1", "Menu 2"};
and use them like this:
Serial.println(menu[0]);
char*
, not an array of char
. And you should handle "Menu 1" as a const char*
, to allow the compiler inhibit you doing nonsense. And avoid warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
Jun 19, 2020 at 14:27
string constant
. But string
(string literals aka const char array) and Arduino String Objects
are so different that we should avoid using the term string completely.
Jun 20, 2020 at 11:19
const char* menu[2] = {"Menu 1", "Menu2"};