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 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) 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; ? Commented Jan 8, 2018 at 14:21
  • 1
    @ShyamMohan You have to use 'T' instead of "T" to compare value with... Commented Jan 8, 2018 at 14:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.