员理管帅最 发表于 2019-9-5 11:35:55

本人写程序,删除出问题了,想了半天,没找出哪出了问题,求大神指点,着急中………

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct NUMBER
{
char name;
char number;
struct NUMBER* next;
};
struct NUMBER*add_number(struct NUMBER**x)
{
    struct NUMBER* team=NULL;
static struct NUMBER* p;
    team=(struct NUMBER*) malloc(sizeof(struct NUMBER));
    if(team==NULL)
{
       printf("申请失败\n");
//      exit(1);
}
else
{
   if(*x==NULL)
   {
    *x=team;
    team->next=NULL;
   }
   else
   {
   p->next=team;
    team->next=NULL;
   }
p=team;
}
return *x;
}
struct NUMBER* luru(struct NUMBER*x)
{
static int count=0;
count++;
for(int i=1;i<count;i++)
{x=x->next;}
printf("请输入名字:");
scanf("%s",x->name);
getchar();
printf("请输入号码:");
scanf("%s",x->number);
getchar();

}

struct NUMBER add_name(struct NUMBER**x)
{
static int count=0;
static struct NUMBER*a;
count++;

if(count==1)
{ a=add_number(x);
   luru(a);}
else
{add_number(&a);
luru(a);}
}
struct NUMBER resoule(struct NUMBER**x)
{
char a;
static struct NUMBER*p;
struct NUMBER*b;
static int count=0;
count++;
if(count==1)
{p=add_number(x);}
printf("请输入想查找姓名:");
scanf("%s",a);
getchar();
b=p;
while(1)
{
if(b==NULL)
{
   printf("无该用户信息\n");
   break;
}
if(!strcmp(a,b->name))
{
   printf("姓名:%s\n",b->name);
   printf("号码:%s\n",b->number);
   break;
}
b=b->next;
}

}
struct NUMBER change(struct NUMBER**x)
{
char a;
static struct NUMBER*p;
struct NUMBER*b;
static int count=0;
count++;
if(count==1)
{p=add_number(x);}
printf("请输入想更改用户:");
scanf("%s",a);
getchar();
b=p;
while(1)
{
if(b==NULL)
{
   printf("无该用户信息\n");
   break;
}
if(!strcmp(a,b->name))
{
   printf("请输入新的号码:");
   scanf("%s",b->number);
   getchar();
   break;
}
b=b->next;
}

}
struct NUMBER clear(struct NUMBER**x)
{
char a,f=0,g=0;
static struct NUMBER*p;
struct NUMBER*b;
struct NUMBER*h;
static int count=0;
count++;
if(count==1)
{p=add_number(x);}
printf("请输入想删除的用户:");
scanf("%s",a);
getchar();
b=p;
while(1)
{
f++;
if(b==NULL)
{
   printf("无该用户信息\n");
   break;
}
if(!strcmp(a,b->name))
{
   g++;
   break;
}
b=b->next;
}
if(g==1)
{
if(f==1)
{
h=p;
p=p->next;
free(h);
}
else
{
for(int i=2;i<f;i++)
   {p=p->next;}
    h=p->next;
p->next=h->next;
free(h);
}
}

}


struct NUMBER(*PANDAUAN(char*x))(struct NUMBER**x)
{
   switch(*x)
{
case '1':return add_name;
case'2':returnresoule;
case'3':returnchange;
case'4':return   clear;
}

}

int main()
{
struct NUMBER*p=NULL;
char a;
printf(" ##    命令集   ##\n");
printf("输入1代表增加联系人\n");
printf("输入2代表查找联系人\n");
printf("输入3代表更改联系人\n");
printf("输入4代表删除联系人\n");
printf(" ###################\n\n");


while(1)
{
printf("请输入指令:\n");
scanf("%c",&a);
getchar();
(*PANDAUAN(&a))(&p);
}

return 0;
}


yuesezhenmei 发表于 2019-9-6 09:33:23

哪里 有问题你那个error怎么提示的 给看下啊 重头看 太麻烦
页: [1]
查看完整版本: 本人写程序,删除出问题了,想了半天,没找出哪出了问题,求大神指点,着急中………