I have two objects, Header, and DF.
lets say
header = CCCCCC7E
and
DF = 01020304
,
shouldnt the value of the buffer be CCCCCC7E01020304
?
for some reason when i printed it i got:
7EFFFFFFCCFFFFFFCCFFFFFFCCFFFFFFCCFFFFFFCCFFFFFFCCFFFFFFCCFFFFFFCCFFFFFFCC00FFFF
FFCC00000000000004030201FFFFFF8967341200000000
this is how i printed it:
for (int i = 0; i < sizeof(buffer); i++)
{ printf("%02X", buffer[i]); }
this is the code:
struct Header header;
struct Data_Format DF;
unsigned char buffer[TOTAL_SIZE];
header.Start = 0x7E;
header.Options = 0x00;
header.PacketLength = 0x00;
header.VCP = 0x00;
header.Reserved = 0x00;
header.Return = 0x00;
DF.Address = 0x01020304; //real value: NULL
DF.Result = 0x1234; //real value: NULL
DF.Size = 0x6789; //real value: NULL
memcpy(buffer,&header, sizeof(Header));
memcpy(buffer+sizeof(Header), &DF, sizeof(Data_Format));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…