数据结构 求改错,我是初学者,哪里错了,该怎么改,完全不知所云
这串代码,就是要实现 建立一个电话簿,可以 输入,删除,插入 其中任意一个用户的 电话号码和名字,然后 还可以 把整个电话薄输出来。。我是初学者,里面好多错误,但是我实在没办法了。。
# 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 编辑 ]