Quote (AbDuCt @ Oct 24 2014 02:20pm)
%u works for any uintX_t types or at least uint8_t.
You can also simply assign it to a unsigned char array.
Code
unsigned char packet[] = {temp->version, temp->ttl, temp->payload };
This may or may not work in your circumstance since the data in the packet had to be added before run time so the compiler can allocate enough space. However you can malloc space for it and assign the data and it would still work.
Alternatively you can specify a packet[x] length and it would work anyways.
Edit:: also FYI, sizeof(*pointer) is always 4 or 8 based on the architecture of your application. You needed to use sizeof() on your struct definition. Also you want to turn it into a byte array, so it should be an unsigned char array.
Yea thanks, my original code was correct just made a mistake when rewriting it here.
Trying sprintf atm, I assume it would be something like this.
Code
char buffer[1024]; // contains msgHeader + msg
struct msgHeader *node;
node = malloc(sizeof(msgHeader));
sprintf(node->version, "%u", buffer));
sprintf(node->ttl, "%u", buffer + sizeof(byte));
ect...