Hello
I was trying to make a SplitString function, but when I try it, my arduino mysteriously rebootes
Here is the function:
String* SplitString(String str, char* car){
String* rtn;
long lng = 0;
char* p;
str.toCharArray(p,str.length());
char* s;
while ((s = strtok_r(p, car, &p)) != NULL){
rtn[lng] = s;
lng++;
}
return rtn;
}
and the code I use to call it:
Serial.println(cmd.substring(5, cmd.length()));
I'm using an Arduino Uno R3
I think it's not an actual reset but something that causes the microcontroller to jump to an address.
I hope someone will help me with this problem
system
January 3, 2017, 2:49pm
2
char* p;
str.toCharArray(p,str.length());
Where does p point to? Do you REALLY think you can write there?
The second argument to the toCharArray() method is NOT the length of the String to be extracted. The instance who's method is being called knows how long it is. The second argument is the length of the ARRAY that the data is to be extracted to.
while ((s = strtok_r(p, car, &p)) != NULL){
rtn[lng] = s;
lng++;
}
Where does rtn point? You can NOT use a pointer like an array until AFTER you make the pointer point to a block of memory.
I dont realy know, I've just modified this:
while ((s = strtok_r(p, car, &p)) != NULL)
Serial.println(s);
to be used in a function
system
January 3, 2017, 3:05pm
4
I've just modified this:
If you don't (as you clearly don't) understand pointers, why are you trying to use them? Arrays are much more obvious.
Now, the obvious issue may be that you don't know how big to make the arrays. We can't help with that, as all that you have posted are snippets.