0

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?

3
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by Nemoticchigga
0

>>&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));

0

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

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

0

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));

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.