1

I'm trying to read compare data from EEPROM (Arduino UNO). Reading is working fine but comparing it using the '==' operator is not working as expected.

//string 'True' is already stored in EEPROM

int addr = 0;
char value = EEPROM.read(addr);

Serial.println(value);// this line successfully prints the letter 'T'

// but this function is not working
if (value == "T") {
  Serial.println("foo");
}
2
  • this has nothing to do with EEPROM ... this is a question about comparing strings
    – jsotola
    Commented Jan 8, 2018 at 18:27
  • I have a problem like I that did you finally fix it. I will be glad if it worked.![Thats the Image](i.sstatic.net/RVqUP.jpg)
    – Sigma
    Commented Sep 16, 2019 at 7:02

1 Answer 1

2

There is a HUGE difference between "string" and 'c' 'h' 'a' 'r'.

You are comparing address of string "T" with the numerical value of character 'T'.

The expression: if (value == 'T') will be much better.

2
  • Thank you for the answer. How can I read and compare the first letter of the string stored at addr = 0; ?
    – smc
    Commented Jan 8, 2018 at 14:21
  • 1
    @ShyamMohan You have to use 'T' instead of "T" to compare value with...
    – KIIV
    Commented Jan 8, 2018 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.