Skip to content

strtok is not working #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hariprasadiit opened this issue May 28, 2015 · 4 comments
Closed

strtok is not working #352

hariprasadiit opened this issue May 28, 2015 · 4 comments

Comments

@hariprasadiit
Copy link

I tried lot of things found in issues to make strtok working,but no luck.

this is my program

include <string.h>

include <stdint.h>

include <stdlib.h>

void setup() {

Serial.begin(115200);

while(1){
if(Serial.available()){
char in = Serial.read();
if(in == 's') break;
Serial.println("send s");
}
delay(10);
}

char rtopic[60] = "hello-LIGHT-L1-POWER";
char* level;
char* thing_cat;
char* thing_id;
char* feature;

level = strtok(rtopic,"-");
thing_cat = strtok(NULL,"-");
thing_id = strtok(NULL,"-");
feature = strtok(NULL,"-");

Serial.println(level);
Serial.println(thing_cat);
Serial.println(thing_id);
Serial.println(feature);

}

void loop() {
// put your main code here, to run repeatedly:

}

its returning the entire string every time.Please point in the right direction if I'm doing something wrong.
same program is working fine with Arduino IDE and Arduino Uno.

@Makuna
Copy link
Collaborator

Makuna commented May 29, 2015

Investigated:
strtok calls strtok_r, strtok_r is broken.

  1. It is allocating memory for the returned string when it should not allocate anything.
  2. It should be returning a pointer into the original string and replacing the found token with a null; it is doing neither of these.
  3. It is returning the a "reentry state" (third param) that is at the last found token but incrementing past it when it uses to start the next state, thus always returning the same as long as the tokens don't change.

I will put out a pull after some testing.

@Makuna
Copy link
Collaborator

Makuna commented May 29, 2015

#357

@igrr
Copy link
Member

igrr commented May 29, 2015

Merged.

@mtnbrit
Copy link

mtnbrit commented Jul 21, 2015

How can I get this fix please? should it already be in 1.6.5?

Normola pushed a commit to Normola/Arduino that referenced this issue Feb 19, 2020
Add Cache-control headers to Javascript & CSS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants