Skip to main content
edited title
Link
Cyber_Star
  • 117
  • 2
  • 8

Comparing 2 char in arduinoconverted from a array

Source Link
Cyber_Star
  • 117
  • 2
  • 8

Comparing 2 char in arduino

I wrote this little program to test converting and comparing 2 char with each other. With some help from [here][1] i have learned that you have to NULL-terminate c stings. But when i try to compare them i still get that they are not equal to each other. this is my program:

char code[4] = {'1','2','3','4'};
char strcode[5];
char pass[4] = {'1','2','3','4'};
char strpass[5];


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


void loop()
{
    memcpy(strcode, code, 5);
    strcode[4] = '\0';
    Serial.println(strcode);
    Serial.println("done");
    delay(1000);
    memcpy(strpass, pass, 5);
    strpass[4] = '\0';
    Serial.println(strpass);
    Serial.println("donepass");
    if (strpass == strcode)
    {
        Serial.println("yes");
    }
    else
    {
        Serial.println("no");
    }
}

I get this in my serial monitor:

1234
done
1234
donepass
no

Why is this not equal to each other? [1]: Converting array to char