I am trying to understand the process by which I can serialize and de-serialize data in C. I wrote code that I believe should write a simple struct to a char buffer.
#include <packet.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
typedef struct
{
int A;
int B;
int C;
}test_packet;
int main(int argc, char** argv)
{
test_packet p;
p.A = 1;
p.B = 2;
p.C = 3;
char buffer [sizeof(p)];
memcpy(buffer, &p, sizeof(p));
printf("%x \n", buffer);
return 0;
}
However, when I run this code, since the struct being serialized is statically coded, I expect to see a buffer that's the same each time. I don't, I see a buffer that appears to be full of random data:
./SerializePacket
41bf5380
./SerializePacket
d89fc790
./SerializePacket
aea2c00
./SerializePacket
d355dc10
Can anyone alleviate me of my ignorance here?