[SOLVED] char *array on lcd

I have the following code and I want to print athe strings splitter to an LCD using I2C.

struct drink{
  char name[30];
  char ingredients [100];
} catalogue = {
  {"Test", "drink 1/drink2/drink3/drink4/drink5"}
};

char *getArray[4]; // store the address for each string
int arrayLength; // total addresses in the getArray

void setup() {
  Serial.begin(115200);

  LCD.init();
  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, "/");
  }
}

The code uploads normally but the esp keeps resetting and I get exception (9) on the serial... Any clues?

I am using the LiquidCrystal_I2C library from
http://gitlab.com/tandembyte/liquidCrystal_i2c

Incomplete example.

But variable names are case sensitive...

 for(int i=0; I < arrayLength; I++) {

Variable “i” is not the same as “I”.

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?

The code that you posted will not compile for a number of reasons

One (of many) is that the catalogue struct data, which is currently

} catalogue =
{
  {"Test", "drink 1/drink2/drink3/drink4/drink5"}
};

should be

} catalogue =
{
  {"Test"}, {"drink 1/drink2/drink3/drink4/drink5"}
};

because you have 2 arrays
so I don't see how you can say

The code uploads normally

Doesn't even come close to compiling.

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, "/");
  }
}
    getArray[arrayLength] = token;

This line will probably crash if 'arrayLength' ever reaches 4.

    LCD.print(getArray[i + 1]); // line2

This will probably crash if 'i' ever reaches arrayLength-1.

pcbbc:

 for(int i=0; I < arrayLength; I++) {

Variable “i” is not the same as “I”.

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!

Thank you once more for your quick response!