|
-
August 18th, 2011, 08:19 AM
#1
Copy buffer to struct
Hi,
i'm receiving some data from an UDP socket, that i would like to copy to a struct/class.
I have defined the following class:
class header
{
public:
unsigned char code;
unsigned char id;
unsigned char length[2];
unsigned char auth[16];
};
I've tried two ways:
First to use memcpy:
header *hdr;
memset(&hdr, 0, sizeof(header));
This works but is not C++.
Second using the following:
header *hdr;
hdr = (header *)data;
Is there a better way to do this?
Or is one of the above the right way?
Thanks in advance 
/Torben
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|