| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 509 人关注过本帖
标题:程序错误~~抠了一周了~~
只看楼主 加入收藏
pokerLee
Rank: 2
等 级:论坛游民
帖 子:41
专家分:29
注 册:2012-11-4
结帖率:93.33%
收藏
已结贴  问题点数:20 回复次数:6 
程序错误~~抠了一周了~~
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
struct Family *get_person(void);
bool related(struct Family *pmember1,struct Family *pmember2);
bool set_ancestry(struct Family *pmember1,struct Family *pmember2);
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;
    struct Family *p_to_ma;
    struct Family *p_to_pa;
};
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;
        }
    }
    current=first;
    while((*current).next!=NULL)
    {
        int parents=0;
        last=(*current).next;
        while(last!=NULL)
        {
            if(related(current,last))
             if(++parents==2)
              break;
            last=(*last).next;
        }
        current=(*current).next;
    }
    current=first;
    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);
        if((*current).p_to_pa!=NULL)
         printf("\n%s's birth date is %d/%d/%d",
                (*current).father,(*current).(*p_to_pa).dob.day,
                (*current).(*p_to_pa).dob.month,
                (*current).(*p_to_pa).dob.year);
        if((*current).p_to_ma!=NULL)
         printf("and %s's birth date is %d/%d/%d.\n",
                (*current).mother,(*current).(*p_to_ma).dob.day,
                (*current).(*p_to_ma).dob.month,
                (*current).(*p_to_ma).dob.year);
        current=(*current).next;
    }
    current=first;
    while(current!=NULL)
    {
        last=current;
        current=(*current).next;
        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 is %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=(*temp).p_to_ma=(*temp).p_to_pa=NULL;
    return temp;
}
bool set_ancestry(struct Family *pmember1,struct Family *pmember2)
{
    if(strcmp((*pmember1).father,(*pmember2).name)==0)
    {
        (*pmember1).p_to_pa=pmember2;
        return true;
    }
    if(strcmp((*pmember1).mother,(*pmember2).name)==0)
    {
        (*pmember1).p_to_ma=pmember2;
        return true;
    }
    else
     return false;
}
bool related(struct Family *pmember1,struct Family *pmember2)
{
    return set_ancestry(pmember1,pmember2)||
     set_ancestry(pmember1,pmember2);
}
编译器是code::blocks的~~错误隐藏的很深啊~~
搜索更多相关主题的帖子: previous include related father mother 
2013-11-06 19:40
pokerLee
Rank: 2
等 级:论坛游民
帖 子:41
专家分:29
注 册:2012-11-4
收藏
得分:0 
编译器报错是74行和79行   expected identifier before "(" token 两行都是这个错误~~
2013-11-06 19:42
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:1 
类似的这种东西有问题
(*current).(*p_to_ma).dob.month

总有那身价贱的人给作业贴回复完整的代码
2013-11-06 21:17
zhaogay
Rank: 7Rank: 7Rank: 7
来 自:宫
等 级:黑侠
帖 子:151
专家分:586
注 册:2013-10-10
收藏
得分:1 
(*current).father这种换成current->father这样的。按照编译器错误找,应该没问题

好好学习,天天想上
2013-11-06 21:35
pangshch
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:2
帖 子:443
专家分:1966
注 册:2013-4-9
收藏
得分:1 
  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);
        if((*current).p_to_pa!=NULL)
         printf("\n%s's birth date is %d/%d/%d",
                (*current).father,(*current).(*p_to_pa).dob.day,   
                (*current).(*p_to_pa).dob.month,
                (*current).(*p_to_pa).dob.year);
        if((*current).p_to_ma!=NULL)
         printf("and %s's birth date is %d/%d/%d.\n",
                (*current).mother,(*current).(*p_to_ma).dob.day,
                (*current).(*p_to_ma).dob.month,
                (*current).(*p_to_ma).dob.year);
        current=(*current).next;
    }
上面红色部分有语法错误, 你把, (*current).(*p_to_pa).dob.day,这样的句子改成(*current).p_to_pa->dob.day;就OK了.
 
坐等高手回答.为什么会产生语法错误
2013-11-08 09:35
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:16 
如果用->就简单了:current->p_to_pa->dob.day
非要用*和.就麻烦了,需要这样:(*((*current).p_to_pa)).dob.day
至于语法错误,不符合语法就产生语法错误。

总有那身价贱的人给作业贴回复完整的代码
2013-11-08 09:57
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:1 
C语言是人发明出来的,它的语法体系是人设计出来,是有逻辑关系的,不是相互孤立的。

总有那身价贱的人给作业贴回复完整的代码
2013-11-08 10:23
快速回复:程序错误~~抠了一周了~~
数据加载中...
 
   



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

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