I wrote this little program to test converting and comparing 2 char with each other. With some help from here 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?