Hello all,
I need some help copying the contents of a struct directly into a char array. Here is what I have as an example:
struct MyStruct{
int x; // 4 bytes
int y; // 4 bytes
char z; // 1 byte
};
MyStruct test;
test.x = 1;
test.y = 2;
test.z = "a";
Then, I would like to create a dynamic array like such:
char *array;
array = (char*)malloc(9);
How can I copy the structs contents into this array (easily). i.e. without iterating through all the members, etc.
Any help is greatly appreciated.
Thanks All!
Sam
I need some help copying the contents of a struct directly into a char array. Here is what I have as an example:
struct MyStruct{
int x; // 4 bytes
int y; // 4 bytes
char z; // 1 byte
};
MyStruct test;
test.x = 1;
test.y = 2;
test.z = "a";
Then, I would like to create a dynamic array like such:
char *array;
array = (char*)malloc(9);
How can I copy the structs contents into this array (easily). i.e. without iterating through all the members, etc.
Any help is greatly appreciated.
Thanks All!
Sam