| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 818 人关注过本帖
标题:数据结构 求改错,我是初学者,哪里错了,该怎么改,完全不知所云
只看楼主 加入收藏
zhuchenxi
Rank: 1
等 级:新手上路
帖 子:61
专家分:6
注 册:2011-4-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
数据结构 求改错,我是初学者,哪里错了,该怎么改,完全不知所云
这串代码,就是要实现  建立一个电话簿,可以  输入,删除,插入 其中任意一个用户的 电话号码和名字,然后 还可以 把整个电话薄输出来。。
我是初学者,里面好多错误,但是我实在没办法了。。  

# include<stdio.h>
# include<stdlib.h>
# include<string.h>
#define OK 1
#define ERROR 0

typedef struct{
    char phonenum[20];
    char name[30];
}yonghu;
typedef struct{
    yonghu *L;
    int length;
}dianhuabu;

int creat_dianhuabu(dianhuabu &P,int n)
{
    yonghu *q,*k;
    if(n<=0) return ERROR;
    P.L=(yonghu *)malloc(n*sizeof(yonghu));
    if(!P.L) return ERROR;
    q=&P.L,k=&P.L[n-1];
    for(;q<=k;q++){
        scanf("%s   %s",&q->phonenum,&q->name);
    }
    P.length=n;
    return OK;
}

int Delete_i(dianhuabu &P,int i,yonghu &e)
{
    int j;
    yonghu *q,*k;
    if(i<0||i>P.length) return ERROR;
    q=&P.L[i-1],k=&P.L[P.length-1];
    e=P.L[i-1];
    for(;q<k;q++){
        *q=*q++;
    }
    P.length--;
    free(P.L[P.length-1]);
    return OK;
}

int Inserti(dianhuabu &P,int i,yonghu &x)
{
    yonghu *q,*k;
    if(i<1) return ERROR;
    P.L=(yonghu *)realloc(P.L,(P.length++)*sizeof(yonghu));
    if(!P.L) return ERROR;
    *q=P.L[i-1],*k=P.L[P.length-1];
    for(;k>=q;k--){
        *k++=*k;
    }
    P.L[i-1]=x;
    P.length++;
    return OK;
}

int printfP(dianhuabu &P)
{
    int i;
    for(i=0;i<P.length;i++){
        printf("%s   %s",P.L[i].phonenum,P.L[i].name);
    }
    return Ok;
}

int main()
{
    char caozuo[20]={' '},A[6]="delete",B[6]="insert",C[1]="0";
    int n,i;
    dianhuabu Q;
    yonghu e,x;
    scanf("%d",&n);
    creat_dianhuabu(Q,n);
    while(1){
        scanf("%s",&caozuo);
        if(strcmp(C,caozuo)!=0) break;
        if(strcmp(A,caozuo)==0){
            scanf("%d",&i);
            Delete_i(Q,i,e);
        }            
        if(strcmp(C,caozuo)==0){
            scanf("%d",&i);
            scanf("%s   %s",&x.phonenum,&x.name);
            Inserti(Q,i,x);
        }
        printfP(Q);
    }
    return 0;
}


这是错误提示:
E:\VC6\Common\MSDev98\Bin\dihuabu.c(16) : error C2143: syntax error : missing ')' before '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(16) : error C2143: syntax error : missing '{' before '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(16) : error C2059: syntax error : '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(16) : error C2059: syntax error : ')'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(30) : error C2143: syntax error : missing ')' before '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(30) : error C2143: syntax error : missing '{' before '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(30) : error C2059: syntax error : '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(30) : error C2059: syntax error : ')'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(45) : error C2143: syntax error : missing ')' before '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(45) : error C2143: syntax error : missing '{' before '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(45) : error C2059: syntax error : '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(45) : error C2059: syntax error : ')'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(60) : error C2143: syntax error : missing ')' before '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(60) : error C2143: syntax error : missing '{' before '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(60) : error C2059: syntax error : '&'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(60) : error C2059: syntax error : ')'
E:\VC6\Common\MSDev98\Bin\dihuabu.c(76) : warning C4013: 'creat_dianhuabu' undefined; assuming extern returning int
E:\VC6\Common\MSDev98\Bin\dihuabu.c(82) : warning C4013: 'Delete_i' undefined; assuming extern returning int
E:\VC6\Common\MSDev98\Bin\dihuabu.c(87) : warning C4013: 'Inserti' undefined; assuming extern returning int
E:\VC6\Common\MSDev98\Bin\dihuabu.c(89) : warning C4013: 'printfP' undefined; assuming extern returning int



[ 本帖最后由 zhuchenxi 于 2011-9-17 22:09 编辑 ]
搜索更多相关主题的帖子: 电话号码 include return 电话簿 
2011-09-17 20:18
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:20 
首现  看看建立的工程中的源文件是否是.c 的  
2011-09-17 21:29
zhuchenxi
Rank: 1
等 级:新手上路
帖 子:61
专家分:6
注 册:2011-4-28
收藏
得分:0 
回复 2楼 寒风中的细雨
是点C的, 用顺序存储结构的太烦了。。。
我刚 用链表的 存储形式 改了下。。。
麻烦版主看下。。。
# include<stdio.h>
# include<stdlib.h>
# include<string.h>
#define OK 1
#define ERROR 0

typedef struct{
    char phonenum[20];
    char name[20];
    struct dianhuabu *next;
}dianhuabu,*DianHuaBu;

int creat_dianhuabu(DianHuaBu P,int n)
{
    int i;
    for(i=0;i<n;i++){
        scanf("%s   %s",&P->phonenum,&P->name);
        P=(dianhuabu *)malloc(sizeof(DianHuaBu));
        P=P->next;
    }
}

int Delete_i(DianHuaBu P,int i,DianHuaBu e,int n)
{
    int j;
    if(i<0||i>n) return ERROR;
    for(j=0;j<i-2;j++){
        P=P->next;
    }
    e=P->next;
    P->next=P->next->next;
    n--;
    return OK;
}

int Inserti(DianHuaBu P,int i,DianHuaBu x,int n)
{
    int j;
    if(i<1) return ERROR;
    P=(dianhuabu *)realloc(P,(n++)*sizeof(DianHuaBu));
    if(!P) return ERROR;
    for(j=0;j<i-1;j++){
        P=P->next;
    }
    x->next=P->next,P->next=x;
    n++;
    return OK;
}

int printfP(DianHuaBu P,int n)
{
    int i;
    for(i=0;i<n;i++){
        printf("%s   %s",P->phonenum,P->name);
        P=P->next;
    }
    return OK;
}

int main()
{
    char caozuo[20]={' '},A[6]="delete",B[6]="insert",C[1]="0";
    int n,i;
    DianHuaBu Q,CR,SC;
    scanf("%d",&n);
    creat_dianhuabu(Q,n);
    while(1){
        scanf("%s",&caozuo);
        if(strcmp(C,caozuo)!=0) break;
        if(strcmp(A,caozuo)==0){
            scanf("%d",&i);
            Delete_i(Q,i,SC,n);
        }            
        if(strcmp(C,caozuo)==0){
            scanf("%d",&i);
            scanf("%s   %s",&CR->phonenum,&CR->name);
            Inserti(Q,i,CR,n);
        }
        printfP(Q,n);
    }
    return 0;
}

2011-09-17 22:09
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
typedef struct{
     char phonenum[20];
     char name[20];
     struct dianhuabu *next;
 }dianhuabu,*DianHuaBu;

这里要改下  不可以匿名  具体什么知识点自己可以寻找答案
typedef struct dianhuabu{
     char phonenum[20];
     char name[20];
     struct dianhuabu *next;
 }dianhuabu,*DianHuaBu;

写程序的时候一定要有适当的提示信息和注释,前者是给用户的后者是给开发人员用的。
在定义变量的时候 最好做下正确的初始化

创建链表的时候 虽然可以按照你的目的接受数据并且把数据连起来 但是没有办法再操作他
因为链表的头已经“释放”掉啦。 非void的返回要带相应的返回类型


scanf("%s   %s",&P->phonenum,&P->name);这里phonenum和name成员要这里不需要区地址,但是取也没什么错

从create开始慢慢写 一个个的函数那样去实现   要保证在正确的基础上再做(开发)下去。  

2011-09-18 00:27
zhuchenxi
Rank: 1
等 级:新手上路
帖 子:61
专家分:6
注 册:2011-4-28
收藏
得分:0 
回复 4楼 寒风中的细雨
版主大人,谢谢啊
2011-09-18 10:04
快速回复:数据结构 求改错,我是初学者,哪里错了,该怎么改,完全不知所云
数据加载中...
 
   



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

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