I am trying to test functionality of strtok() on a Rocketscream V3 (without radio), as I ran out of memory to develop on my Nano. This is a basic example from the internet involving tokenizing the string and reporting the tokenized entries via SerialUSB.
#include <string.h>
void setup() {
char *token;
char *mystring = "apples,pears,bananas";
SerialUSB.begin(9600);
while (!SerialUSB) { }
SerialUSB.print("Serial established");
token = strtok(mystring, ",");
while (token != NULL) {
SerialUSB.println(token);
token=strtok(NULL, ",");
}
}
The code works as expected on my Nano (with Serial instead of SerialUSB), but while it does compile for the Arduino Zero, it never makes it past printing “Serial established”. I have confirmed this by including code (serial print, LED flashing) past the tokenization parts, and these are never executed. The loop() function is never reached, it seems to halt at “token = strtok(mystring, “,”);”.
I cannot think of a simpler possible way to test strtok(), but it’s just not working. Any help would be appreciated.