The "new" errors:
main.c:14:34: error: ‘p.father’ is a pointer; did you mean to use
‘->’? 14 | p.name, p.age, p.father.name, p.mother.name);
| ^
| -> main.c:14:49: error: ‘p.mother’ is a pointer; did you mean to use ‘->’? 14 |
p.name, p.age, p.father.name, p.mother.name);
| ^
| -> main.c: In function ‘main’: main.c:28:19: error: incompatible types when
assigning to type ‘struct Person *’ from type ‘struct Person’ 28 |
bart.mother = marge;
| ^~~~~ main.c:29:19: error: incompatible types when assigning to type ‘struct Person *’ from type ‘struct
Person’ 29 | bart.father = homer;
| ^~~~~
I need to fix this snippet so that it works. On the first run the compiler shows me this:
main.c:7:19: error: field ‘mother’ has incomplete type
7 | struct Person mother;
| ^~~~~~ main.c:8:19: error: field ‘father’ has incomplete type
8 | struct Person father;
|
^~~~~~
#include <stdio.h>
struct Person {
int age;
char* name;
struct Person mother; //i guess it's somthing wrong here
struct Person father; //i guess it's somthing wrong here
};
void showPerson(struct Person p) {
printf("Name: %s\nAge: %d\nFather: %s, Mother: %s\n",
p.name, p.age, p.father.name, p.mother.name); }
int main() {
struct Person homer; //and here also wrong
struct Person marge; //and here also wrong
struct Person bart; //and here also wrong
homer.age = 36;
homer.name = "Homer";
marge.age = 34;
marge.name = "Marge";
bart.age = 10;
bart.name = "Bart";
bart.mother = marge;
bart.father = homer;
showPerson(bart);
return 0;
}