I am receiving over ethernet into a 'char messageBuffer[512]' and then passing it on by a function call to 'process((char*) messageBuffer)' then in process:

void process(char* theMessage)
{
	myStruct messageBuffer;

	memcpy(&myStruct, &theMessage, sizeof(theMessage));   //this line is wrong

}

Im not sure how to properly put it back into myStuct once it is received. myStruct is how the data was sent and now I want to put it back in and see it correctly.

Any input would be appreciated. Thanks.

P.S. Why arent the code tags working?

Recommended Answers

All 6 Replies

>>&theMessage
That make it a pointer to a pointer. You don't need the & symbol because theMessage is already a pointer memcpy(&myStruct, theMessage, sizeof(theMessage));

memcpy(&myStruct, theMessage, sizeof(theMessage));

This still does not put the correct values back into the struct. Any other suggestions?

Oooh - what's the size of a ptr AD ;)

duhhhh! :icon_redface:

memcpy(&myStruct, theMessage, sizeof(theMessage));

This still does not put the correct values back into the struct. Any other suggestions?

My post was just a tad bit wrong -- the size of any pointer is on 4 on all 32-bit compilers. What you want is the size of the structure

memcpy(&myStruct, theMessage, sizeof(myStruct));

Wow, Im an idiot. That fixed it. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.