A complex if

Hello folks !
I'm a total beginner in Arduino, and it was originally not going to be a part of my project, but my team mate doing it didn't really do it, ahah.
Here is the code :

  if (client.available())
   {
      
      Serial.print("From client: \"");
      while (client.available())
      {
      Serial.print((char)client.read());
      }
      Serial.println("\"");
   }

So, I tried many time to put a condition inside the while, like if(strcmp((var)client.read(), "blah" == 0). I want to check if the string received through client.read() equals the word blah. I tried many things but never succeeded as my understanding of the little gears of C is small. Can anyone show me an example I could use and learn from ?
Thank you in advance !
Regards

Almost...

if(strcmp((var)client.read(), "blah") == 0)

if that's what you were trying to write.
You need to get the () to balance in the right places.

.read() returns only one character - no good for comparing with "blah", so you may need to go back to the drawing board. There are MANY examples of reading & parsing from character streams.

Not sure what the (var) is for.

  if (client.available())
   {
      
      Serial.print("From client: \"");
      while (client.available())
      {
      character = client.read();
      content.concat(character);
      delay(10);
      }
      Serial.println("\"");
      const char* content2 = content.c_str();
      Serial.print(content2);
      if(strcmp(content2, "blah") == 0) {
        Serial.print("Positive match");
      }
      
   }

That is what I wrote, and it seems to be right, but when content2 contains blah, strcmp still doesn’t kick in :frowning:

      while (client.available())
      {
      Serial.print((char)client.read());
      character = client.read();

Don’t call read() twice, dude.

An alternative to using strcmp is:

char check[] = "commandQ";

if (client.available())
{
  boolean positiveMatch = true;
  boolean matchAt = 0;
     
  Serial.print("From client: \"");
  while (client.available())
  {
    char ch = (char) client.read();
   
    Serial.print(ch);
    if(ch == '\n') { // end of line
      if(check[matchAt] != '\0') positiveMatch = false;
      break;
    }
    else if(check[matchAt] == '\0') { // don't increment matchAt!!
      positiveMatch = false;
    }
    else if(check[matchAt++] != ch) {
      positiveMatch = false;
    }
  }

  Serial.println("\"");
  if(positiveMatch) {
    Serial.print("Positive match");
  }
}

Mind you - this won’t handle the situation when your input comes in in chunks.