Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Slice string at ":"

I need to slice a string (eg- 4:288:18464:288:4) at ":" into an array({4, 288, 18464, 288, 4}) I used the following code, but its giving only '4' in the serial monitor when "4:288:18464:288:4," is given to arduino.

void displayString(char* s)
{
 char* text = strtok(s,":");
 while(text != NULL){
 text = strtok(NULL,":");}
}
void loop()
{
 if(Serial.available() > 0)
 {
 str = Serial.readStringUntil(',');
 str.toCharArray(text,99);
 }
 displayString(text);
Serial.println(text);
}

Answer*

Draft saved
Draft discarded
Cancel

AltStyle によって変換されたページ (->オリジナル) /