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");
}
dda
1,5951 gold badge12 silver badges17 bronze badges
asked Jan 8, 2018 at 14:13
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.

answered Jan 8, 2018 at 14:17
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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.