Skip to main content
Arduino

Return to Revisions

1 of 2
user3826856
  • 83
  • 1
  • 2
  • 4

Splice string at ":"

I need to splice 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);
}
user3826856
  • 83
  • 1
  • 2
  • 4

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