Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef unsigned char byte;
typedef struct complex
{
int a,b;
} complex;
int main()
{
complex z,t;
byte a[1024];
z.a=1;
z.b=4;
memcpy(a,&z,sizeof(z));
memcpy(&t,a,sizeof(struct complex));
printf("%d %d\n",t.a,t.b);
return 0;
}
this works just fine I guess. I was wondering if I can do something like index a part from that array like a structure. something like:
Code:
((struct complex)a).a=1;
((struct complex)a).b=4;
or maybe something like this:
Code:
complex z,t;
void *p;
z.a=1;
z.b=4;
p=&z;
t.a=(complex*)p->a;
t.b=(complex*)p->b;
the last 2 code snippets don't work are just a hint of what I'm trying to do!