How to send a char

Hello,
I want to send a char to another device. But I got an error message from my Arduino mega 2560. The message:

"invalid operands of types 'const char [10]' and 'char [0]' to binary 'operator+'"

Here is my code:

struct dataType{ 
  char name1[]; 
  int userTemp1; 
  float userThickness1;
};
dataType d;

String command1="ABCD";

void setup(){
  Serial.begin(9600); 
}


void loop(){

       strcpy(d.name1, "USER1");            
       d.userTemp1 = 150; //default 150C
       d.userThickness1 = 1.0; //default 1.0T

command1="t10.txt=\""+d.name1+"\"";

Serial.print(command1);

}

Can someone teach me where goes wrong?

this line.. "strcpy(d.name1, "USER1");" is jamming 6 bytes into unallocated memory.

"command1="t10.txt=""+d.name1+""";" I'm thinking this line causes a compiler error. I can't figure out what it does.

-jim lee

Do not use the String class with and Arduino. There is limited memory and zero garbage collection so in the end this technique will fail. Use the string class, note lower case s, it is a whole different thing.

I want to send a char to another device.

But you seem to be trying to send a string not a character?

To send a string use:-

Serial.print("my string here");

To send a character use

Serial.write(c); // where the variable c ( type chr ) is the exact bit pattern you want to send

jimLee:
this line.. "strcpy(d.name1, "USER1");" is jamming 6 bytes into unallocated memory.

"command1="t10.txt=""+d.name1+""";" I'm thinking this line causes a compiler error. I can't figure out what it does.

-jim lee

Thanks. You are right, it's the line which shows error.

I did not post full my code since it is huge. 'd.name1' is a char I stored in internal EEPROM. And I like to load it and send to Nextion LCD device allocates to t10.txt display.

There's no need to glue together a string and send the whole string as a single command. Just send each fragment that needs to be sent....

Serial.print("t10.txt=\"");
Serial.print(d.name1);
Serial.print("\"");