Return to Snippet

Revision: 1354
at September 27, 2006 14:37 by brentroady

Initial Code
#pragma pack(1)
typedef struct
    int id;
    char[50] text;

// Send a message
MESSAGE msg; = 1;
strcpy(msg.text, "This is a test");
send(socket, (char*)&msg);

// Receive a message
char buffer[100];
recv(socket, buffer, 100);
MESSAGE* msg = (MESSAGE*)buffer;
printf("id=%d\n", msg->id);
printf("text=%s\n", msg->text);

Initial URL

Initial Description

Initial Title
Mapping a byte array to a struct in C

Initial Tags

Initial Language