how to assign a char to variable in a struct

Hi,

In the code below, I create a struct and assign values to the field.

How can assign a char called newidtest to the a field in the struct?

I get the following error:

error: invalid conversion from 'char*' to 'char'

struct messagePacket {
   char boardID[3];       
   char temperature[3];
   };

   struct messagePacket myPacket;


   void setup() {
   char idtest;
   struct messagePacket myPacket;

   Serial.begin(9600);
   strcpy(myPacket.boardID, "01");
   strcpy(myPacket.temperature, "75");
  
   Serial.print("ID = ");
   Serial.println(myPacket.boardID);

   newidtest = myPacket.boardID;
   Serial.println(newidtest);
   }
   void loop() {
}

Thanks

1 Like

idtest is a single char, boardID is an array of 3 chars.

Thats like trying to pump 3 gallons of diesel into a 1 gallon can.

make idtest into a char array of similar size, and strcpy it like your doing. alternatively just print it out straight:

 Serial.println(myPacket.boardID);

Thanks for explaining :slight_smile: