Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

strtok_r Problem

$
0
0
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
.
.
.
 

 


Viewing all articles
Browse latest Browse all 2077

Trending Articles