KrisKasprzak
Well-known member
All,
I'm writing a small menu system library where I would like to pass in an array of chars and have that array be stored with a certain menu item--kinda hard to explain...
Can anyone take a look at my pseodo code below and see if you can figure out how to pass an array of chars and have that array save with a specific char in a .h, I'm really stuck
// i have this array definition in my my .ino
const char *CarText[] = {"Blue", "Red", "White"};
// calling function to my library
// trust me this all works umnil I added the char array
MenuOption6 = MyMenu.add(1.2, CarText);
/////////// INO code
// goal to call in my function
MyMenu.draw();
// and on screen would print
Blue
Red
White
/////////////////// .h code
// method inside my library
int add(float Increment, const char *MenuText[] = NULL) {
ID++;
inc[ID] = Increment;
// I know this is wrong, but tried everything but the working solution
// may need to use strcpy not not sure how to get the number of elements to loop through
menutext[ID] = MenuText;
return(ID);
}
void draw(int TheID) {
// set color, cursor and all that jaz
d->print(menutext[TheID][0]);
d->print(menutext[TheID][1]);
d->print(menutext[TheID][2]);
}
private:
float inc[MAX_OPTION];
char menutext[MAX_OPTION];
I'm writing a small menu system library where I would like to pass in an array of chars and have that array be stored with a certain menu item--kinda hard to explain...
Can anyone take a look at my pseodo code below and see if you can figure out how to pass an array of chars and have that array save with a specific char in a .h, I'm really stuck
// i have this array definition in my my .ino
const char *CarText[] = {"Blue", "Red", "White"};
// calling function to my library
// trust me this all works umnil I added the char array
MenuOption6 = MyMenu.add(1.2, CarText);
/////////// INO code
// goal to call in my function
MyMenu.draw();
// and on screen would print
Blue
Red
White
/////////////////// .h code
// method inside my library
int add(float Increment, const char *MenuText[] = NULL) {
ID++;
inc[ID] = Increment;
// I know this is wrong, but tried everything but the working solution
// may need to use strcpy not not sure how to get the number of elements to loop through
menutext[ID] = MenuText;
return(ID);
}
void draw(int TheID) {
// set color, cursor and all that jaz
d->print(menutext[TheID][0]);
d->print(menutext[TheID][1]);
d->print(menutext[TheID][2]);
}
private:
float inc[MAX_OPTION];
char menutext[MAX_OPTION];