Substring of a C string

I'm having a similar problem:
I want to check if a c-style string starts with a specific string constant.
I'm using strstr() but in trying to test and understand it, I can't figure out what is happening.

char data[] = "/set color #FF8080";
void setup() {
 Serial.begin(9600);
 Serial.println(data);
 int i = strstr(data,"/set ");
 Serial.println(i);
}

void loop() {


}

The output for i is 256. Why wouldn't it be 0?

Don't hijack an existing thread. Most of us won't look at a thread that has already been answered.

Instead, start a new thread, and if your question is similar you can reference this thread.

ddzahn:
I'm having a similar problem:
I want to check if a c-style string starts with a specific string constant.
I'm using strstr() but in trying to test and understand it, I can't figure out what is happening.

char data[] = "/set color #FF8080";

void setup() {
Serial.begin(9600);
Serial.println(data);
int i = strstr(data,"/set ");
Serial.println(i);
}

void loop() {

}




The output for i is 256. Why wouldn't it be 0?

strstr() returns a pointer, not an index

The contents of i is the location in memory where the target string resides. Add three (printable) characters to the front of data and note what i holds after a run.

Topic split from an old one

If what you want to check is supposed to be at the start of the cString you could use strncmp() and use the length of your known string as nb of chars to check