strtok_P() and strtok_rP() on WiFi Rev 2 to parse querystring

Hello, I would like to, eventually, parse a querystring which looks something like this: http://192.168.1.81/?username=myUsername&password=myPassword.

I was planning on using the strtok() or strtok_r() functions, but it doesn't appear to be available on the WiFi Rev 2, but strtok_P() and strtok_rP() are available. However, they don't work for me because I get the full line string of text rather than parsed data. Here's an example of one of my attempts:

                char str[] = "Geeks for Geeks";
                char* token;
                char* rest = str;
                while ((token = strtok_rP(rest, " ", &rest))) {
                    Serial.println(token);
                };

The output is: Geeks for Geeks.
The output should be:
Geeks
for
Geeks

So, I was wondering two things:

a) why aren't strtok() and strtok_r() available, and is it okay to continue using strtok_rP()?
b) why is the strtok_rP() not parsing correctly, and how do I get it to parse properly?

https://www.google.de/search?q=arduino+demo+"strtok_P()"
found this

some more explanation quogleld

by the way which Arduino-Board are you using?
I guess that this is a very important information.
best regards Stefan

Hello, Stefan - the board is the WiFi Rev 2. I had tried the suggestion of using variables in PROGMEM (after finding it via Google), but it didn't work for me either.

Hello

Try strtok_rP(rest, PSTR(" "), &rest)

They SHOULD be available...
What makes you think they aren't?
The following (complete, minimal (hint)) sketch compiles fine for a Uno WiFi2.
(I don't actually have a UW2, so I didn't actually test it...)

void setup() {
  char str[] = "Geeks for Geeks";
  char* token;
  char* rest = str;
  while ((token = strtok_r(rest, " ", &rest))) {
    Serial.println(token);
  };
}
void loop() {}

how did you test? agree with @westfw that the compiler does not complain.

Sorry for the delay in responding - busy week. The issue was with Visual Studio (VS) IDE. I didn't bother to try to reconfigure VS, I switched to processing the String in a loop. I know, I know...not efficient, but I prefer to use VS and the string is very short. Anyhow, thanks for the answers/responses - all of your feedback pointed me to evaluate the difference between the Arduino IDE compiling and the VS IDE compiling. (not sure which to mark as solution, they were all helpful)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.