Yes it is possible.
There are various ways to do this. The following are two simple methods.
struct myStruct myVar; ... memcpy (foo, &myVar, sizeof (myStruct));
Or if you are dealing with a pointer ...
struct myStruct * myVarPtr; ... memcpy (foo, myVarPtr, sizeof (myStruct));
Note that when copying a structure to / from an array of characters like this, you should be very careful, since the dimensions of the structure are not always what you might think first. In your particular case there can be no problems; but in general, you should at least be aware of the possible fill, alignment, and font size issues that might change the size of your structure.
Hope this helps.
source share