Splitting a passed string into multiple strings

I read a great post on splitting a string into multiple strings based on a ptr and delimiter but had problems implementing in my project...

code excerpt....


void setup() {
  char str[] = "strtok needs to be called several times to split a string";
  char delim[] = " ";
  char *ptr = strtok(str, delim);
  Serial.begin(115200);
  while(ptr != NULL)
  {
    Serial.println(ptr);
    ptr = strtok(NULL, delim);
  }
}

void loop() {
}

OK, I have a project with two TTGO LoRa32 SX1276 OLED passing weather data from one to another...
I tried implementing the example but it looks as if that example starts with a predefined string within quotes...

String LoRaData;
.
.
.
  //read packet
   while (LoRa.available()) {
     LoRaData = LoRa.readString();
     Serial.println(LoRaData);
     **char str[]=LoRaData;**
     char delim[]="*";
     char *ptr=strtok(str, delim);
     while (ptr != NULL){
       Serial.println(ptr);
       ptr=strtok(NULL, delim);
     }
   }

if the line 'char str[]=LoRaData;' was encased in quotes I think it would work as the example did but that is where I am stuck.
The error I'm getting is that it cannot convert 'String' to 'char' in assignment.

Try:

   char buf[LoRaData.length()+1];
   memset(buf, 0, sizeof buf);
   strncpy(buf, LoRaData.c_str(), (sizeof buf)-1);
   char delim[]="*";
   char *ptr=strtok(buf, delim);

ditto..

String LoRaData = "Hello*From*Lora";
 if (LoRaData.length()> 0){
     char str[LoRaData.length()+1];
     strcpy(str,LoRaData.c_str());
     char delim[]="*";
     char *ptr=strtok(str, delim);
     while (ptr != NULL){
       Serial.println(ptr);
       ptr=strtok(NULL, delim);
     }
 }

good luck.. ~q

van_der_decken...
I applied your suggestion and it compiled w/o errors...
This will give me something to work with.
Thank you very much!

char s [80];

// -----------------------------------------------------------------------------
#define MaxTok  20
char *toks [MaxTok];
int   vals [MaxTok];

int
tokenize (
    char       *s,
    const char *sep )
{
    unsigned n = 0;
    toks [n] = strtok (s, sep);
    vals [n] = atoi (toks [n]);

    for (n = 1; (toks [n] = strtok (NULL, sep)); n++)
        vals [n] = atoi (toks [n]);

    return n;
}

// -----------------------------------------------------------------------------
void dispToks (
    char * toks [])
{
    char s [40];
    for (unsigned n = 0; toks [n]; n++)  {
        sprintf (s, " %6d  %s", vals [n], toks [n]);
        Serial.println (s);
    }
}

// -----------------------------------------------------------------------------
void loop ()
{
    if (Serial.available ())  {
        int n = Serial. readBytesUntil ('\n', s, sizeof(s)-1);
        s [n] = 0;      // terminate string

        tokenize (s, " ");
        dispToks (toks);
    }
}

// -----------------------------------------------------------------------------
char str[] = "strtok needs to be called several times to split a string";


void setup ()
{
    Serial.begin (9600);
    tokenize (str, " ");
    dispToks (toks);
}