user84598: I am trying to compare two string but each time i am getting awkward results. When i use Equals() function i always get the wrong answer and never satisfy the IF statement. When i use compareTo() function i always get the right answer (which is btw not correct) but it always just satisfy the IF statement.
String input;
String Answer = "cat";

void setup()
{
  Serial.begin(19200);
}

void loop()
{
  while (Serial.available() == 0)
  {
    Serial.readStringUntil('\n');
    if (input.equals(Answer))
    {
      Serial.println(input + ", Correct");
    }
    else
    {
      Serial.println(input + ", wrong");
    }
  }
}

Above is the code i am using to learn the string Comparison.

user7508: You have defined a variable named input, but you never assign a value
to it. It should thus always have its initial value, which is an empty
string.
Here:
Serial.readStringUntil('\n');

you probably meant
input = Serial.readStringUntil('\n');


84598: <p>I am trying to compare two string but each time i am getting awkward results. When i use Equals() function i always get the wrong answer and never satisfy the IF statement. When i use compareTo() function i always get the right answer (which is btw not correct) but it always just satisfy the IF statement.</p>
<pre class="lang-cpp prettyprint-override"><code>String input;
String Answer = &quot;cat&quot;;

void setup()
{
  Serial.begin(19200);
}

void loop()
{
  while (Serial.available() == 0)
  {
    Serial.readStringUntil('\n');
    if (input.equals(Answer))
    {
      Serial.println(input + &quot;, Correct&quot;);
    }
    else
    {
      Serial.println(input + &quot;, wrong&quot;);
    }
  }
}
</code></pre>
<p>Above is the code i am using to learn the string Comparison.</p>
 7508: <p>You have defined a variable named <code>input</code>, but you never assign a value
to it. It should thus always have its initial value, which is an empty
string.</p>
<p>Here:</p>
<pre class="lang-cpp prettyprint-override"><code>Serial.readStringUntil('\n');
</code></pre>
<p>you probably meant</p>
<pre class="lang-cpp prettyprint-override"><code>input = Serial.readStringUntil('\n');
</code></pre>
