StefanWxx 2 Posted August 6, 2014 Share Posted August 6, 2014 Hi, a simple program and also a simple problem, but I can not find a solution. someone has a tip for me? char text[] = "Value1, 1000, Value2,100,Value3,1.414,end"; void setup() { Serial.begin(9600); } void loop(){ char *p = text; char *str; while ((str = strtok_r(p, ",", &p)) != NULL) // delimiter is comma { Serial.println(str); delay(500); } } The output ist not as expected: Value1 1000 Value2 100 Value3 1.414 end Value1 Value1 Value1 Value1 Value1 Value1 Value1 . . . . . I want this: Value1 1000 Value2 100 Value3 1.414 end Value1 1000 Value2 100 Value3 1.414 end Value1 1000 Value2 100 Value3 1.414 end . . . Quote Link to post Share on other sites
oPossum 1,083 Posted August 6, 2014 Share Posted August 6, 2014 char *strtok_r(char *str, const char *delim, char **saveptr); On the first call to strtok_r(), str should point to the string to be parsed, and the value of saveptr is ignored. In subsequent calls, str should be NULL, and saveptr should be unchanged since the previous call. char *p = text; char *q; char *str; while ((str = strtok_r(p, ",", &q)) != NULL) // delimiter is comma { p = NULL; Serial.println(str); delay(500); } StefanWxx 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.