Explain in a simple example. How to pass a char* to a function?
#define name1 "ABCD"
#define name2 "EFGH"
#define name3 "HIJK"
char *list[3] = {};
void printList(char *l, int x) {
for (int i = 0; i < x; i++) {
Serial.println(l[i]);
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("start");
list[0] = name1;
list[1] = name2;
list[2] = name3;
printList(list, 3);
}
void loop() {
// put your main code here, to run repeatedly:
}
I get an error:
/home/guy/Documents/Dropbox/Arduino/sketch_jun12a/sketch_jun12a.ino: In function 'void setup()':
sketch_jun12a:24:13: error: cannot convert 'char**' to 'char*'
24 | printList(list, 3);
| ^~~~
| |
| char**
/home/guy/Documents/Dropbox/Arduino/sketch_jun12a/sketch_jun12a.ino:7:22: note: initializing argument 1 of 'void printList(char*, int)'
7 | void printList(char *l, int x) {
| ~~~~~~^
exit status 1
cannot convert 'char**' to 'char*'