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");
}
3

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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