I have a byte array created like this in my C source file:
static char arr[64];
I also have a struct declared like so:
static char arr[64];
struct test {
int foo;
int data;
};
If everything in memory is just bytes, how could I store the bytes of of a test
struct inside of arr
I have tried the following things:
int main() {
struct test t;
t.foo = 255;
t.data = 364;
arr[0] = t; // This did not work; I got a type-mismatch
// I also tried memcpy
memcpy(arr, &t, 8); // But this did not work either because it does not store the data in array. I was also not able to deference the bytes that did get stored.
}
Is there any easy way that I can store the bytes of the test
struct in the byte array arr
so that I can store multiple structures in this array and access it easily too?
If everything is just bytes, is there a feasible way to store the test
struct bytes in the arr
array?