电话号码查询C语言
#include
#include
#include
struct comm *mylist;
struct comm
{
char name[20];
char mail[10];
char phone[15];
struct comm *next;
};
void Store();
void Display();
void Delete();
void Select();
void main()
{
int i,m=1;
mylist=(struct comm *)malloc(sizeof(struct comm));
mylist->next=NULL;
//char p[5];
// printf("-----\n");
//gets(p);
//printf("%s",p);
while(m)
{
//printf("0.存取 1.显示 2.删除 3.查询 4.退出\n 请输入:");
printf("*********************\n");
printf(" 1.存取信息 \n");
printf(" 2.显示信息 \n");
printf(" 3.删除信息 \n");
printf(" 4.查询信息 \n");
printf(" 5.退出 \n");
printf("*********************\n");
printf("请输入选择:");
scanf("%d",&i);
switch(i)
{
case 1: Store();break;
case 2: Display();break;
case 3: Delete();break;
case 4: Select();break;
case 5: m=0;break;
default: printf("error"); break;
}
}
getchar();
}
void Store()
{
struct comm *cursor,*temp; cursor = mylist;
while(cursor->next!=NULL)
{
cursor=cursor->next;
}
temp=(struct comm *)malloc(sizeof(struct comm));
temp->next=NULL;
printf("请输入姓名:");
scanf("%s",temp->name); printf("请输入邮编:");
scanf("%s",temp->mail); printf("请输入电话:");
scanf("%s",temp->phone); cursor->next=temp;
}
void Display()
{
struct comm *cursor,*temp; cursor=mylist;
while(cursor->next!=NULL)
{
cursor=cursor->next;
printf(" 姓名:"); puts(cursor->name); printf(" 邮编:"); puts(cursor->mail); printf(" 电话:"); puts(cursor->phone);
}
}
void Delete()
{
char name[20];
struct comm *cursor,*temp; cursor=mylist;
printf("请输入要删除的姓名:");
scanf("%s",name);
while(cursor->next!=NULL)
{
if(!strcmp(name,cursor->next->name))
{
temp=cursor->next;
cursor->next=temp->next;
break;
}
cursor=cursor->next;
}
printf("删除成功~\n");
}
void Select()
{
char name[20];
struct comm *cursor,*temp; cursor=mylist;
printf("请输入要查询的姓名:");
scanf("%s",name);
while(cursor->next!=NULL)
{
if(!strcmp(name,cursor->next->name))
{
printf(" 姓名:"); puts(cursor->next->name);
printf(" 邮编:"); puts(cursor->next->mail);
printf(" 电话:"); puts(cursor->next->phone);
break;
}
cursor=cursor->next;
}
if(cursor->next==NULL) printf("无该姓名~\n"); }