错误:取消引用指向不完整类型的‘结构体’指针
程序代码:
/* Program 11.6 Basics of a family tree */ #include <stdio.h> #include <ctype.h> #include <stdlib.h> struct Family *get_person(void); struct Date { int day; int month; int year; }; struct Family { struct Date dob; char name[20]; char father[20]; char mother[20]; struct Family *next; struct Family *previous; }; int main(void) { struct Family *first = NULL; /*第一个*/ struct Family *current = NULL; /*当前*/ struct family *last = NULL; /*最后一个*/ char more = '\0'; for( ; ;) { printf("\nDo you want to enter details of a%s person (Y or N)? ", first != NULL?"nother " : ""); scanf(" %c", &more ); if(tolower(more) == 'n') break; current = get_person(); if(first == NULL) /*只在第一次输入执行*/ { first = current; last = current; } else { last->next = current; current->previous = last; last = current; } } while(current != NULL) /*链表输出*/ { printf("\n%s was born %d%d%d, and has %s and %s as parents.", current->name, current->dob.day, current->dob.month, current->dob.year, current->father, current->mother); last = current; current = current->previous; free(last); } return 0; } struct Family *get_person(void)/*读取输入*/ { struct Family *temp; temp = (struct Family*) malloc(sizeof(struct Family)); printf("\nEnter the name of the person: "); scanf("%s", temp -> name); printf("\nEnter %s's date of birth (day month year); ", temp-> name); scanf("%d %d %d", &temp -> dob.day, &temp->dob.month, &temp->dob.year); printf("\nWho id %s's father? ", temp -> name); scanf("%s", temp -> father); printf("\nWho is %s's mother? ", temp -> name); scanf("%s", temp -> mother); temp->next = temp->previous = NULL; return temp; }
书中示例,为了演示返回结构指针
编译提示 :49 error: dereferencing pointer to incomplete type 'struct family'|
请问是哪里出错了?
预谢!
[此贴子已经被作者于2019-5-19 16:49编辑过]