鱼C论坛

 找回密码
 立即注册
查看: 1685|回复: 1

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

[复制链接]
发表于 2019-9-5 11:35:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct NUMBER
{
  char name[20];
  char number[20];
  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[20];
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[20];
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[20],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':return  resoule;
case'3':return  change;
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;
}


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-9-6 09:33:23 | 显示全部楼层
哪里 有问题  你那个error怎么提示的 给看下啊 重头看 太麻烦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-4 07:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表