标题:错误:取消引用指向不完整类型的‘结构体’指针
只看楼主
bxe
Rank: 1
等 级:新手上路
帖 子:57
专家分:7
注 册:2019-3-21
结帖率:72.22%
已结贴  问题点数:20 回复次数:1 
错误:取消引用指向不完整类型的‘结构体’指针
程序代码:
/* 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编辑过]

搜索更多相关主题的帖子: struct name NULL current temp 
2019-05-19 16:42
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:20 
struct family *last = NULL; /*最后一个*/
struct Family *last = NULL; /*最后一个*/
2019-05-20 08:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-494813-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.425850 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved