运行结果
初始界面
选项界面
源代码:
#include<stdio.h>#include<stdlib.h>
typedef struct Maillink
{
char ID[20];
char name[20];
char phone[20];
char add[80];
char tel[20];
struct Maillink *p;
}mk;
mk *head=NULL,*tail=NULL,*untail=NULL;
int i;
static mk Mail;
void prefix()
{
printf ("\033[33m\033[2J");
for ( i=0; i<10; i++)
printf (" ");
for ( i=0; i<50; i++)
printf("\033[33m*\033[0m");
printf ("\n\n");
}
void suffix()
{
printf ("\n");
for ( i=0; i<10; i++ )
printf (" ");
for ( i=0; i<50; i++ )
printf ("\033[33m*\033[0m");
printf ("\n");
for ( i=0; i<10; i++ )
printf (" ");
printf ("\033[37mPress Enter key to end \033[0m");
getchar();
}
void output()
{
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mname: %s\033[0m",tail->name);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mID: %s\033[0m",tail->ID);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mphone: %s\033[0m",tail->phone);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30maddress: %s\033[0m",tail->add);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mfilm TEL: %s\n\033[0m",tail->tel);
}
int add()
{
prefix();
mk *mk_head;
mk_head=(mk *)malloc(sizeof(mk));
if (mk_head==NULL)
{
printf("creat error!\n");
return -1;
}
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mplease enter name: \033[0m");
fgets (mk_head->name,20,stdin);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mplease enter firm ID: \033[0m");
fgets (mk_head->ID,20,stdin);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mplease enter phone: \033[0m");
fgets (mk_head->phone,20,stdin);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mplease enter address: \033[0m");
fgets (mk_head->add,80,stdin);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mplease enter firm TEL: \033[0m");
fgets (mk_head->tel,20,stdin);
suffix();
mk_head->p=NULL;
tail=&Mail;
while( (tail->p) != NULL )
tail=tail->p;
tail->p=mk_head;
sort();
}
int sort()
{
mk jia,bao,yu;
int i=1;
while(i)
{
tail=&Mail;tail=tail->p;
head=tail;tail=tail->p;
i=0;
while(tail!=NULL)
{
if ( strcmp((head->ID),(tail->ID))>0 )
{
jia=*head;
bao=*tail;
*tail=jia;
*head=bao;
tail->p=bao.p;
head->p=jia.p;
i++;
}
tail=tail->p;
head=head->p;
}
}
}
void lookup()
{
prefix();
tail=&Mail;
tail=tail->p;
while(tail!=NULL)
{
output();
tail=tail->p;
printf("\n");
}
suffix();
}
void search()
{
prefix();
char sname[20];
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mplease enter name: \033[0m");
fgets(sname,20,stdin);
printf("\n");
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mResult:\n\033[0m");
tail=&Mail;
int i=0;
tail=&Mail;
while(tail!=NULL)
{
if(!(strcmp(tail->name,sname)))
{
output();
i++;
}
tail=tail->p;
}
if (0==i)
{
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mNOT FIND\033[0m");
}
suffix();
}
void del()
{
prefix();
char sname[20];
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mplease enter delect friend name: \033[0m");
fgets (sname,20,stdin);
printf("\n\n");
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mResult:\n\033[0m");
int j=0;
tail=&Mail;tail=tail->p;
while (tail!=NULL)
{
if (!(strcmp( tail->name,sname)))
j++;
tail=tail->p;
}
if (0==j)
{
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mNOT FIND!\n\033[0m");
}
if (1==j)
{
tail=&Mail, head=&Mail;
tail=tail->p;
while (tail!=NULL)
{
if ( !(strcmp(tail->name,sname) ) )
{
head->p=tail->p;
free (tail);
tail=head;
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mDelect Success!\n\033[0m");
}
tail=tail->p;
head=head->p;
}
}
if(j>1)
{
tail=&Mail;
while(tail!=NULL)
{
if(!(strcmp(tail->name,sname)))
output();
tail=tail->p;
}
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mplease enter delect ID: \033[0m");
char id[20];
fgets(id,20,stdin);
tail=&Mail; head=&Mail;
tail=tail->p;
while(tail!=NULL)
{
if (!(strcmp(tail->ID,id)))
{
head->p=tail->p;
free(tail);
for(i=0;i<15;i++)
printf(" ");
printf ("\033[30mDelect success!\n\033[0m");
tail=head;
}
tail=tail->p;
head=head->p;
}
}
suffix();
}
void face()
{
int i;
for(i=0;i<10;i++)
printf(" ");
for(i=0;i<50;i++)
printf("\033[32m*\033[0m");
printf("\n");
for(i=0;i<23;i++)
printf(" ");
printf("\033[31m Electonic Address Book \033[0m");
printf("\n\n\n");
for(i=0;i<15;i++)
printf(" ");
printf("\033[31m 1:Add buddy info\n \033[0m");
for(i=0;i<14;i++)
printf(" ");
printf("\033[31m 2:See book\n \033[0m");
for(i=0;i<14;i++)
printf(" ");
printf("\033[31m 3:Search buddy\n \033[0m");
for(i=0;i<14;i++)
printf(" ");
printf("\033[31m 4:Delete buddy\n \033[0m");
for(i=0;i<14;i++)
printf(" ");
printf("\033[31m 5:Quit\n\n\033[0m");
for(i=0;i<15;i++)
printf(" ");
printf("\033[31m Enter Number:\n\n\033[0m");
for(i=0;i<52;i++)
printf(" ");
printf("\033[37m BY SU\n\n\033[0m");
for(i=0;i<10;i++)
printf(" ");
for(i=0;i<50;i++)
printf("\033[32m*\033[0m");
printf("\033[30m\033[4A");
printf("\033[31m\033[31D");
}
int main()
{
Mail.p=NULL;
char n[4];
while(1)
{
printf("\033[33m\033[2J");
printf("\033[30m\033[100A");
printf("\033[30m\033[100D");
face();
fgets(n,3,stdin);
printf("\033[30m\033[100A");
printf("\033[30m\033[100D");
if('\n'!=n[1])
continue;
if('1'==n[0])
add();
if('2'==n[0])
lookup();
if('3'==n[0])
search();
if('4'==n[0])
del();
if('5'==n[0])
{
printf("\033[33m\033[2J");
return 0;
}
}
}