Tried copying structure pointer to structure which is possible while the reverse is not possible: Can someone help out? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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)); }

21st Feb 2019, 6:43 PM
Ranjani Sathyamurthy
Ranjani Sathyamurthy - avatar
1 Antwort
+ 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
21st Feb 2019, 7:25 PM
Ipang