I have code like this
main.c
....
....
struct dta
{
int id;
char *val;
};
....
....
int main(void)
{
struct dta *dt = malloc(sizeof(*dt));
dt->id=8;
dt->val=strdup("123456qwerty");
foo1(dt);
free(.........);
free(.........);
return 0;
}
void foo1(struct dta *dt)
{
foo2(dt);
}
void foo2(struct dta *dt)
{
foo3(dt);
}
void foo3(struct dta *dt)
{
free(dt->val);
dt->val=strdup("asdfg123456");
dt->id=18;
bar(dt);
}
void bar(struct dta *dt)
{
printf("id = %d\n", dt->id);
printf("val = %s\n", dt->val);
}
I do not know what to do, I just learned c language. I want to display the data dt->* that I created in main () to bar (). Firts, I have dt->* from main, I call and pass dt->* to foo1(), foo1() call foo2() and pass dt->* to foo3(). And I want to print dt->* from bar(). Please someone help me. The problem is foo3() can't update dt->* on main().