I'm trying to read from the EEPROM and combine the information and send it out over SoftwareSerial using write() function but i'm getting the following error

error: invalid operands of types 'const char [3]' and 'const char*' to binary 'operator+'

void loop()  
  const char* eTest1 = EEPROM.read(1);
  const char* eTest2 = EEPROM.read(2);
  const char* eTest3 = EEPROM.read(3);

  char combinedVal[] = eTest1+":"+eTest2+":"+eTest3;
  • btw: for a C string (char array terminated with 0), the write function is same as print() – Juraj Jul 29 '19 at 11:06

You cannot use the + operator for that.

However, since EEPROM.read only returns one byte and not a string, you can do a much easier implementation:

void loop()  
  char result[] = "1:2:3";
  for (int item = 0; item < 3; item++)
    result[item * 2] = EEPROM.read(1 + item);

This first create a string "1:2:3", where the digits are overwritten in the for loop by that item. Note that the digits in the string do not matter, it's just some free 'comment', it also should work when using "x:x:x".

| improve this answer | |
  • Ok thats great it trys to combined them but comes up with the following error warning: invalid conversion from 'uint8_t {aka unsigned char}' to 'const char*' [-fpermissive] const char* eTest1 = EEPROM.read(1); ^ – Rickstar Jul 29 '19 at 11:41
  • @Rickstar I made a better implementation, since EEPROM.read always returns exactly one byte (character). – Michel Keijzers Jul 29 '19 at 11:54
  • @Rickstar EEPROM.read() returns one byte, not a pointer to string. – KIIV Jul 29 '19 at 11:56
  • Thanks @MichelKeijzers – Rickstar Jul 29 '19 at 12:00
  • You're welcome. – Michel Keijzers Jul 29 '19 at 12:30

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.