I have this struct:
struct Msg
{
unsigned char header;
unsigned short length;
char* data;
};
What I want, is to pass this struct through a socket, that is, to convert it into a char array.
I guess something like this will not work:
...makeMsg(MessageHeader id,char* data,int datasize)
{
Msg msg;
msg.header=(unsigned char)id;
msg.length=datasize;
msg.data=data;
char* msgstr = new char[sizeof(Msg)];
memcpy(msgstr,&msg,sizeof(Msg));
...
}
It won't copy the data I guess... since it's of a variable width.How can I make it work?


Sign In
Create Account


Back to top









