|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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;
}
|
|