#include
#include
#include
#include
#define ASK(top)
#define LEN sizeof(ADDR)
extern int count;
typedef struct address
{char name[8];
char tel[20];
struct address *next;
}ADDR;
struct address *head;
struct address *p; int n;
ADDR *input()
{
p=head;
while(p!=NULL)
{scanf("%s %s\n",p->name,p->tel);
p=p->next;
n++;}
return head;
}
void display(ADDR *head)
{
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%s %s\n",p->name,p->tel);
p=p->next;
}while(p!=NULL);
}
ADDR del(ADDR *head)
{ char name[8];
if(head==NULL)
{printf("\nlist null!\n");return *head;}
p=head;
while(p!=NULL)
{
int j;char str1[8];char str2[8];
for(j=0;j
{str1[j]=name[j];str2[j]=name[j];}
if(strcmp(str1,str2)==0)
{if(p==head) head=p->next;
else p=p->next;
printf("delete:%s %s\n",p->name,p->tel);
n=n-1;
}
else p=p->next;
}
return *head;
}
int handle_menu(ADDR *)
{
int c;
printf("\n1.input address's data\n");
printf("\n2.display address's data\n");
printf("\n3.delete address's data\n");
printf("\n4.Goodbye!");
printf("please input your selecion 1-5:");
scanf("%d\n",&c);
return c;
}
void main()
{
ADDR *top;
ASK(top);top=head;
top->next=NULL;
count=0;
handle_menu(top);
int d;
for(;;)
{d=handle_menu(top);
switch(d)
{case 1:input();break;
case 2:display(top);break;
case 3:del(top);break;
case 4:printf("Goodbye!");
default:printf("input error!please input again!\n");break;
}
}
}