I'm currently trying to cut a char into several pieces of text.
void setup() {
Serial.begin(115200);
char data[] = "test,ca,va?,,test";
char sep[] = ",";
String *liste;
liste = cutString(data,sep);
Serial.println(liste[0]);
}
String * cutString(char data[],char sep[]){
Serial.begin(115200);
int number = 0;
int size = String(data).length();
for (int i = 0; i < size; i++){
if(data[i]==sep[0]){
number ++;
}
}
String * list;
char *d = strtok(data, ",");
list[0]=String(d);
int i =1;
while (d != NULL) {
d = strtok(NULL, ",");
list[i] = String(d);
i++;
}
return list;
}
void loop() {
// put your main code here, to run repeatedly:
}
There is my code.
Everything works fine in the cutString function (when i do serial print, I retrieve what I want), but when called, I think there is something wrong, as nothing appears in serial monitor, and no build issue.
I tried to do some things to debug my code, but I didn't removed these modifications. At the begining, I wanted to have a function taking a char input, a char separator, to return a list of all separated characters.
I agree with you that I did crazy things here, but I was very lost with all of that. Can you help me do it the good way please ?