I am trying to convert the following structure to a char array so that I can send it through the serial port.
struct foo { uint16_t voltage; char ID ; char TempByte; char RTCday[2]; char RTCmonth[2]; char RTCyear[2]; char RTChour[2]; char RTCmin[2]; char Sepbyte; }dvar = { 500, 'X' , '>' , "18" , "10" , "15" , "20" , "15" , '#'};
Then I convert it to a char array using the following:
char b[sizeof(struct foo)]; memcpy(b, &dvar, sizeof(struct foo));
However, for some reason, I get these final values ββin a char array
0x0A 0xFF
Initially, I thought it was getting values, because when I passed it to a char array, it effectively cast it to a string, so although it was NULL '\ 0'
Any help would be appreciated.
thanks
source share