Recursive strstr always returns !=NULL

I'm working on making my code more dynamic and I'm storing all my ds18b20 sensor data in a two dimensional array. Everything is working perfectly except one part.

I'm defining my data like this...

typedef struct {
  DeviceAddress addr;
  char name[8];
  float temp;
  float setpoint;
} Sensor;

Sensor sensor_list[] = {
  { { 0x28, 0xFF, 0x46, 0x82, 0x58, 0x16, 0x04, 0x9A }, "zone0", 45.00, 44.44 },
  { { 0x28, 0xFF, 0x8F, 0x59, 0x58, 0x16, 0x04, 0xDE }, "zone1", 45.00, 44.44 }
};

I'm able to update that temperature (in the 3rd column in the array) with no problem. I can read my sensors without issue. The one thing I'm having an issue with is parsing my MQTT topics that come in to grab that setpoint. If I do...

void callback(char* topic, byte* payload, unsigned int length) {
for (int i=0;i<length;i++) {
payload[length] = '\0';

cstring = (char *) payload;
}
//Serial.println(topic);  //This is the topic
// Serial.println(cstring); //this is the payload
request = atof(cstring);

if (strstr(topic, "setpoint") != NULL) {
  for (unsigned i = 0; i < sizeof(sensor_list) / sizeof(Sensor); i++) {
    setpoint = atof(cstring);
    if (strstr(topic, "1") != NULL) {
      sensor_list[i].setpoint = setpoint;
    }
  }

}
}

It updates EVERY row of the array with the setpoint it receives from MQTT. Pretty much every version of this code that I've tried either updates every row or zero rows.

Can someone help me understand my logic error?

sorry...this line was a test of giving it a static value...

if (strstr(topic, "1") != NULL) {

it's

if (strstr(topic, i) != NULL) {

and the problem persists with that code.

And just as an example, the topic comes in as

/company/campus/building/room/zone with zone being the i in the for loop.
Although, I would be perfectly fine with it coming in as
/company/campus/building/room/zone0 with zone0 being the name attribute in Sensor.

The second argument to strstr must be a character string. Giving it an integer isn't going to succeed.
You'll have to convert 'i' into a string and use that.

BTW. There's nothing about your use of strstr that is recursive.

Pete

for (int i=0;i<length;i++) {
payload[length] = '\0';

cstring = (char *) payload;
}

Why do you need to put the NULL in the same place in the array more than once? Why do you need to point to the start of the array more than once?

el_supremo:
BTW. There's nothing about your use of strstr that is recursive.
Pete

Well, it was a strstr inside of a strstr and the first one worked and the second one didn't. That's what I meant by recursive.

What you mean by recursive and what recursive actually means are two very different things.

Pete