<span style="font-size:18px;">#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
#include<conio.h>
#define LEN sizeof(struct ab)
#define ZIP 7
#define PHONE 7
#define MAX 100
struct ab
{
char name[10];
char addr[10];
char zip[ZIP];
char phone[PHONE];
struct ab *next;
};
struct ab *head;
void search(struct ab *head);
struct ab *add(struct ab *head);
struct ab *del(struct ab *head);
void alter(struct ab *head);
void print(struct ab *head);
void thefirst();
int n;</span>
<span style="font-size:18px;">#include"head.h"
void main()
{
n=0;
head=(struct ab *)malloc(LEN);
thefirst();
}
void thefirst()
{
char c;
system("CLS");
puts("**************************************");
puts(" 通讯录 ");
puts(" 1、查询 ");
puts(" 2、加入 ");
puts(" 3、删除 ");
puts(" 4、改动 ");
puts(" 5、显示 ");
puts(" 6、返回 ");
puts("**************************************");
c=getch();
system("CLS");
switch(c)
{
case '1':search(head);break;
case '2':head=add(head);thefirst();break;
case '3':head=del(head);thefirst();break;
case '4':alter(head);break;
case '5':print(head);break;
case '6':printf("BYE BYE!\n");
}
}</span>
<span style="font-size:18px;">#include"head.h"
void search(struct ab *head)
{
char str[10];
struct ab *p;
p=head;
printf("please input the name you want to search!\n");
scanf("%s",str);
if(p==NULL)
{
printf("please input the information first!press any key to thefirst \n");
getch();
thefirst();
}
system("CLS");
for(;p&&strcmp(str,p->name);p=p->next);
if(p)
printf("%10s\n%10s\n%10s\n%10s\n",p->name,p->addr,p->zip,p->phone);
else
printf("there is no information about the people you want!\n");
getch();
thefirst();
}</span>
<span style="font-size:18px;">#include"head.h"
struct ab *add(struct ab *head)
{
struct ab *p1,*p2,*p3;
char c[10];
printf("please input the name!\n");
scanf("%s",c);
p1=head;
if(n==0)
{
strcpy(p1->name,c);
printf("please input the address!\n");
scanf("%s",p1->addr);
printf("please input the zip!\n");
scanf("%s",p1->zip);
printf("please input the phone!\n");
scanf("%s",p1->phone);
printf("%s\n",p1->phone);
p1->next=NULL;
n++;
}
else
{
p3=(struct ab *)malloc(LEN);
strcpy(p3->name,c);
printf("please input the address!\n");
scanf("%s",p3->addr);
printf("please input the zip!\n");
scanf("%s",p3->zip);
printf("please input the phone!\n");
scanf("%s",p3->phone);
if(strcmp(c,p1->name)<0)
{
head=p3;
p3->next=p1;
}
else
{
for(;p1&&strcmp(c,p1->name)>0;p2=p1,p1=p1->next);
if(p1==NULL)
{
p2->next=p3;
p3->next=NULL;
}
else
{
p2->next=p3;
p3->next=p1;
}
n++;
}
}
return head;
}</span>
<span style="font-size:18px;">#include"head.h"
struct ab *del(struct ab *head)
{
struct ab *p1,*p2;
char c[10];
p1=head;
printf("please input the name you want to delete\n");
scanf("%s",c);
for(;p1&&strcmp(c,p1->name);p2=p1,p1=p1->next);
if(p1==NULL)
{
printf("not find!press any key to thefirst \n");
getch();
}
else if(p1==head)
head=p1->next;
else
p2->next=p1->next;
return head;
}</span>
<span style="font-size:18px;">#include"head.h"
void alter(struct ab *head)
{
char str[10];
struct ab *p;
p=head;
printf("please input the name you want to search!\n");
scanf("%s",str);
for(;p&&strcmp(str,p->name);p=p->next);
if(p)
{
printf("please input the address!\n");
scanf("%s",p->addr);
printf("please input the zip!\n");
scanf("%s",p->zip);
printf("please input the phone!\n");
scanf("%s",p->phone);
}
else
{
printf("not find!press any key to thefirst \n");
getch();
}
thefirst();
}
</span>
<span style="font-size:18px;">#include"head.h"
void print(struct ab *head)
{
struct ab *p;
for(p=head;p;p=p->next)
{
printf("%10s%10s%10s%10s\n",p->name,p->addr,p->zip,p->phone);
}
getch();
thefirst();
}</span>