I'm having problems using two strtok (), one within the while () of the other, the first variable receives the value returned from strtok () to traverse a while () and within the while () a second variable receives the value of strtok () of the first variable and when that second variable receives the value the while does not run the second time and if I comment the line with the second variable it runs.
In the example I am testing I have a char array that separates the parameters by '#' and then I get the params and break through the '=' to get the parameter name and value.
Why does the second variable make the first 'lost'?
My code:
void loop()
{
char teste[ ] = "action=getData#time=121341234";
char* pch;
char* pch2;
char* stringAux;
int cont = 0;
pch = strtok (teste,"#");
while (pch != NULL)
{
if(strstr(pch, "=")) {
Serial.print(F("IF: "));
Serial.print(pch);
cont = 0;
pch2 = strtok (pch, "=");
}
pch = strtok (NULL, "#");
}
while(1);
}