Edit: Also your function “split” only takes a single parameter. You are passing two parameters in the call.
Please post complete compilable examples. If you do not know what is wrong with your code you are not qualified to decide what to show others for them to identify the problem. Do you take only your car key to the garage because it won’t start the car?
sketch_jul29a:9:1: error: too many initializers for 'char [30]'
};
^
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:9:1: warning: missing initializer for member 'drink::ingredients' [-Wmissing-field-initializers]
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino: In function 'void setup()':
sketch_jul29a:18:3: error: 'LCD' was not declared in this scope
LCD.init();
^~~
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:18:3: note: suggested alternative: 'ACD'
LCD.init();
^~~
ACD
sketch_jul29a:21:35: error: too many arguments to function 'void split(char*)'
split(catalogue.ingredients, "/"); // split the char array to tokens
^
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:39:6: note: declared here
void split(char input[])
^~~~~
sketch_jul29a:25:19: error: 'I' was not declared in this scope
for (int i = 0; I < arrayLength; I++)
^
sketch_jul29a:28:5: error: 'lcd' was not declared in this scope
lcd.print(getArray[i]); // line1
^~~
exit status 1
too many initializers for 'char [30]'
Here is what it might look like with the compile errors fixed:
#include <LiquidCrystal.h>
struct drink
{
char name[30];
char ingredients [100];
} catalogue =
{"Test", "drink 1/drink2/drink3/drink4/drink5"} ;
LiquidCrystal LCD(1, 2, 3, 4, 5, 6);
char *getArray[4]; // store the address for each string
int arrayLength; // total addresses in the getArray
void setup()
{
Serial.begin(115200);
//LCD.init();
LCD.begin(20, 4);
LCD.clear();
split(catalogue.ingredients); // split the char array to tokens
// Print a token in each line
for (int i = 0; i < arrayLength; i++)
{
LCD.clear();
LCD.print(getArray[i]); // line1
LCD.setCursor(0, 1);
LCD.print(getArray[i + 1]); // line2
delay(3000);
}
}
void loop() {}
// Split a char array with "/" delimiter
void split(char input[])
{
char *token;
arrayLength = 0;
token = strtok(input, "/");
while ( token != NULL)
{
getArray[arrayLength] = token;
arrayLength++;
token = strtok(NULL, "/");
}
}
Edit: Also your function “split” only takes a single parameter. You are passing two parameters in the call.
You are right about that, I was writing the question from my phone, because I have limited internet to post from my laptop and copy paste the whole code, since I am in the middle of the Pacific right now...
Problem solved, I was incrementing i twice in the for loop and overflow the memory, deleted that and now it's working as intended!