标题:数据结构 求改错,我是初学者,哪里错了,该怎么改,完全不知所云
取消只看楼主
zhuchenxi
Rank: 1
等 级:新手上路
帖 子:61
专家分:6
注 册:2011-4-28
结帖率:100%
已结贴  问题点数:20 回复次数:2 
数据结构 求改错,我是初学者,哪里错了,该怎么改,完全不知所云
这串代码,就是要实现  建立一个电话簿,可以  输入,删除,插入 其中任意一个用户的 电话号码和名字,然后 还可以 把整个电话薄输出来。。
我是初学者,里面好多错误,但是我实在没办法了。。  

# 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
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
zhuchenxi
Rank: 1
等 级:新手上路
帖 子:61
专家分:6
注 册:2011-4-28
得分:0 
回复 4楼 寒风中的细雨
版主大人,谢谢啊
2011-09-18 10:04



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




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

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