Go Down

Topic: problems reading data from Processing in arduino (Read 880 times) previous topic - next topic

PaulS

Quote
any ideas?

Yes. The strtok_r() function is quite complex, and intended for use on multithreaded systems. Since you are not using threads on the Arduino (for good reason; you can't), there is no reason to use a thread-safe version of the strtok() function. The strtok() function has two other advantages. First, it is a lot smaller. Second, it is a lot less complicated.

Finally, "but this wouldnt work for me" doesn't mean squat. The code did something. You expected it to do something. What either of those somethings is is not at all clear.

However, look at what you are doing. You are parsing a string pointed to by p. Then, you store the token in p. Then, you set p to NULL, and expect to get the next token from a NULL string. How can you possibly expect to get a token from a NULL string?

lordprimoz

how would you use the strtok() function then?
say i have my input array filled with 090;090;00;0;0;0;0 ( input[18] )
and i would want to read out the first 3 values  090, 090 and 00. ( the others will be for later, i dont need them at this time)

PaulS

Quote
how would you use the strtok() function then?
say i have my input array filled with 090;090;00;0;0;0;0 ( input[18] )
and i would want to read out the first 3 values  090, 090 and 00.

Code: [Select]
int tokenCount = 0;
int tokenValues[3];

char *token = strtok(input, ",");
while(token && tokenCount < 3)
{
   // Do something with token
   tokenValues[tokenCount++] = atoi(token);

   token = strtok(NULL, ",");
}

// Now, tokenValues[] contains 90, 90, and 0

lordprimoz


Go Up