该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#ifdef _H_LETTER_H_A
#define _H_LETTER_H_A
#include
#include
#include
#include
#define ASK(p) do
{\
p=(ADDR*) malloc (sizeof(ADDR));\
if(p==NULL)
{
printf("memory fail!");
exit(-1);
}\
}while(0)
#define LEN sizeof(ADDR)
extern int conut;
typedef struct address
{
char name[8];
char tel[20];
struct address *next;
}ADDR;
ADDR *input(ADDR *);
void display(ADDR *);
int menu_select(void);
void handle_menu(ADDR *);
ADDR *del(ADDR *);
#endif
#include"record.h"
int count;
void main()
{
ADDR *top,*star;
ASK(top);
ASK(star);
top->next=NULL;
count=0;
handle_menu(top);
}
void handle_menu(ADDR *top)
{
for(;;)
{
switch(menu_select())
{
case 1:top=input(top);break;
case 2:display(top);break;
case 3:top=del(top);break;
case 4:printf("quit,goodbye!\n");
exit(0);
}
}
}
int menu_select()
{
char s[2];
int cn=0;
printf("\n");
printf("1.input the record.\n");
printf("2.display the record.\n");
printf("3.delete the record.\n");
printf("4.end.\n");
printf("The number go with the function,make a choice!");
for(;;)
{
gets(s);
ch=atoi(s);
if(cn<1||cn>6)
printf("\nInput is wrong,try again:");
else
break;
}
return cn;
}
#include"record.h"
ADDR *input(ADDR *top)
{
ADDR *old;
ADDR *star;
ASK(star);
old=top;
while(old->next!=NULL)
{
old=old->next;
}
printf("input the static,0 will end.\n");
--count;
do
{
++count;
printf("daihao:");
gets(star->name);
if(strcmp(star->name,"0")==0)
break;
printf("telephone:");
gets(star->tel);
if(count==0)
top=star;
old->next=star;
old=star;
ASK(star);
}while(star->name[0]!='0');
old->next=NULL;
free(star);
return(top);
}
void display(ADDR *top)
{
ADDR *p;
if(count==0)
{
printf("\nNot found!\n");
return;
}
p=top;
printf("\n All the record is follow:%d:\n",count);
while(p!=NULL)
{
printf("%s\t%s\n",p->name,p->count);
p=p->next;
}
}
#include"record.h"
ADDR *del(ADDR *top)
{
char choose[5],input[30];
int cn=0;
ADDR *old,*star;
if(count==0)
{
printf("record had been empty,quit!");
return top;
}
printf("1.by daihao\n");
printf("2.bu number\n");
gets(choose);
while(1)
{
cn==atoi(choose);
if(cn!=1&&cn!=2)
{
printf("input is wrong,try again:");
gets(choose);
}
else
break;
}
switch(cn)
{
case 1:printf("input the daihao:");break;
case 2:printf("input the number:");
}
gets(input);
old=star=top;
while(star!=NULL)
{
if((cn==2&&strcmp(input,star->tel)==0))
{
if(star==top)
top=star->next;
else
old->next=star->next;
free(star);
--count;
printf("delete...");
if(count==0)
{
ASK(top);
ASK(star);
top->next=NULL;
}
return top;
}
else
{
old=star;
star=star->next;
}
}
printf("not found!");
return top;
}