Having trouble with simple if statement comparison

Hey All,
I'm stuck on a seemingly easy if statement comparison.

How can get this if statement to work?

Thx
Rich

void ledControl(char* topic, byte* payload, unsigned int length) {

  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);  // this renders as expected
  }
  Serial.println(topic); // this renders as expected

  if (topic == '/hangingLamp/stream') {  // I can't seem to get this comparison to work
    Serial.println("bull sandwhich");
  }
}
if (strcmp(topic, "/hangingLamp/stream") == 0)

You have two errors:

Character string constants (C-strings, zero terminated character arrays) are enclosed in double quotes, like "hello".

C-strings are compared using the functions strcmp or strncmp.

if (strcmp(topic,"hello") == 0) Serial.println("match");

1 Like

Thanks for the quick responses everyone!

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