0
Tried copying structure pointer to structure which is possible while the reverse is not possible: Can someone help out?
typedef struct test { int a; int b; } test1_t; typedef struct core { int c; test1_t t; } typedef struct rcb { int c; test1_t *t; } void copy (rcb_t *rcb1, core_t *ptr); int main() { core_t *ptr; rcb_t *rcb; rcb_t *rcb1; rcb_t r,r1; r.c = 5; r1.c = 0; r.t = (test1_t *) malloc(sizeof(test1_t)); r1.t = (test1_t *) malloc(sizeof(test1_t)); r.t->b = 6; r.t->a = 4; r1.t->a = 8; r1.t->b = 9; rcb = &r; ptr->c = rcb->c; if(rcb->t) { memcpy(&ptr->t, rcb->t, sizeof(test1_t)); } rcb = &r1; copy(rcb1,ptr); return 0; } void copy (rcb_t *rcb1, core_t *ptr) { rcb->c = ptr->c; memcpy(rcb1->t->b, &(ptr->t.b),sizeof(test1_t)); }
2 Réponses
+ 6
Please remove the following thread because you have a better description of the topic and have good response on this thread. Hope you understand 👍
https://www.sololearn.com/Discuss/1697994/?ref=app