Casting from struct to char array and vice versa
Hi I want to ask about casting in C.
If I have a struct c in which contains 2 integers a and b, and I want cast it to a char array, so I did this
When I tried to revert back to c struct and access the values of a and b I encounter some access reading violation reading location error.
c* pter = (c*)malloc(sizeof(c));
c* revert = (c*)malloc(sizeof(c));
pter = &c1;
pter->a = 5;
ch = (char)pter;
revert = (c*)t;
printf("priting revert c.a is %d",revert->a);
printf("priting revert c.b is %d",revert->b);
Any ideas what is wrong here? is this the way to do it?