任何管理系统的框架都是一样的(增删改查)学会任何一个就可以编写其他管理系统
在编写管理系统前需要熟练使用结构体,指针和数组(结构体指针或结构体数组都可以编写管理系统,本程序为结构体指针)
需要先进行信息录入,每录入一个人的信息点击1退出录入进行其他操作,2继续录入
退出后(输入1)再输入2可查看
#include<stdio.h>
#include<stdlib.h>#include<string.h>
#include<malloc.h>
#define number 50
#define NULL 0
#define LEN sizeof(struct address)
#define cent "%s %d %d %s %s %s %s"
struct address
{
char name[20];
char num[20];
char qq[20];
char wei[20];
char email[20];
char trat[20];
char work[20];
struct address *next;
};
struct address *head;
static int n=0;
void scan(struct address *g)
{
printf("请输入:姓名:");
scanf("%s",g->name);
printf("请输入:电话:");
scanf("%s",g->num);
printf("请输入:QQ:");
scanf("%s",g->qq);
printf("请输入:微信:");
scanf("%s",g->wei);
printf("请输入:邮箱:");
scanf("%s",g->email);
printf("请输入:贯籍:");
scanf("%s",g->trat);
printf("请输入:工作单位:");
scanf("%s",g->work);
}
int menu_select()
{
int choice;
printf("*********************************************************************\n");
printf(" 通讯管理系统 \n");
printf("*********************************************************************\n");
printf(" 1:信息录入 \n");
printf(" 2:信息浏览 \n");
printf(" 3:信息查询 \n");
printf(" 4:信息修改 \n");
printf(" 5:信息插入 \n");
printf(" 6:信息删除 \n");
printf(" 7:按姓名排序 \n");
printf(" 8:系统退出 \n");
printf("请输入您的选择:");
scanf("%d",&choice);
return choice;
}
struct address * add()
{
int temp;
struct address *p1,*p2;
p2=p1=(struct address *)malloc(LEN);
head=NULL;
while(1)
{
n=n+1;
printf("第%d个人.\n",n);
if(n==1) head=p1;
else p2->next=p1;
scan(p1);
p2=p1;
p1=(struct address *)malloc(LEN);
printf("如果你想退出,请输入1;如果你想继续,请输入2:");
scanf("%d",&temp);
if(temp==1) break;
}
p2->next=NULL;
return head;
}
void look(struct address *head)
{
struct address *p;
p=head;
printf("*********************************************************************\n");
printf("姓名\t电话\tQQ\t微信\t邮箱\t贯籍\t工作单位\n");
printf("*********************************************************************\n");
if(head!=NULL)
{
while(p!=NULL)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
p=p->next;
}
}
}
int find_nenu()
{
int choice;
printf("*********************************************************************\n");
printf(" 查找联系人 \n");
printf("*********************************************************************\n");
printf(" 1:姓名查找 \n");
printf(" 2:电话查找 \n");
printf(" 3:QQ查找 \n");
printf(" 4:微信查找 \n");
printf(" 5:邮箱查找 \n");
printf(" 6:贯籍查找 \n");
printf(" 7:工作单位查找 \n");
printf(" 8:退出查找 \n");
printf("请输入您的选择:");
scanf("%d",&choice);
return choice;
}
void find_cpy(struct address *head)
{
struct address *p;
char good[20];
int temp=find_nenu();
p=head;
printf("请输入所查找的联系人的联系方式:");
scanf("%s",good);
if(temp==1)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->name)==0)
{
printf("*********************************************************************\n");
printf("姓名\t电话\tQQ\t微信\t邮箱\t贯籍\t工作单位\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("*********************************************************************\n");
}
p=p->next;
}
}
}
else if(temp==2)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->num)==0)
{
printf("*********************************************************************\n");
printf("姓名\t电话\tQQ\t微信\t邮箱\t贯籍\t工作单位\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("*********************************************************************\n");
}
p=p->next;
}
}
}
else if(temp==3)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->qq)==0)
{
printf("*********************************************************************\n");
printf("姓名\t电话\tQQ\t微信\t邮箱\t贯籍\t工作单位\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("*********************************************************************\n");
}
p=p->next;
}
}
}
else if(temp==4)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->wei)==0)
{
printf("*********************************************************************\n");
printf("姓名\t电话\tQQ\t微信\t邮箱\t贯籍\t工作单位\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("*********************************************************************\n");
}
p=p->next;
}
}
}
else if(temp==5)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->email)==0)
{
printf("*********************************************************************\n");
printf("姓名\t电话\tQQ\t微信\t邮箱\t贯籍\t工作单位\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("*********************************************************************\n");
}
p=p->next;
}
}
}
else if(temp==6)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->trat)==0)
{
printf("*********************************************************************\n");
printf("姓名\t电话\tQQ\t微信\t邮箱\t贯籍\t工作单位\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("*********************************************************************\n");
}
p=p->next;
}
}
}
else if(temp==7)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->work)==0)
{
printf("*********************************************************************\n");
printf("姓名\t电话\tQQ\t微信\t邮箱\t贯籍\t工作单位\n");
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("*********************************************************************\n");
}
p=p->next;
}
}
}
}
void find(struct address *head)
{
while(1)
{
int temp;
find_cpy(head);
printf("如果你想退出,请输入8;如果你想继续,请输入9:");
scanf("%d",&temp);
if(temp==8)
{
break;
}
}
}
void change_cpy(struct address *head)
{
struct address *p;
char good[20];
int temp=find_nenu();
p=head;
printf("请输入想修改的联系人的联系方式:");
scanf("%s",good);
if(temp==1)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->name)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("请输入你要修改的:\n");
scan(p);
break;
}
p=p->next;
}
}
}
else if(temp==2)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->num)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("请输入你要修改的:\n");
scan(p);
}
p=p->next;
}
}
}
else if(temp==3)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->qq)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("请输入你要修改的:\n");
scan(p);
}
p=p->next;
}
}
}
else if(temp==4)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->wei)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("请输入你要修改的:\n");
scan(p);
}
p=p->next;
}
}
}
else if(temp==5)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->email)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("请输入你要修改的:\n");
scan(p);
}
p=p->next;
}
}
}
else if(temp==6)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->trat)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("请输入你要修改的:\n");
scan(p);
}
p=p->next;
}
}
}
else if(temp==7)
{
if(head!=NULL)
{
while(p!=NULL)
{
if(strcmp(good,p->work)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",p->name,p->num,p->qq,p->wei,p->email,p->trat,p->work);
printf("请输入你要修改的:\n");
scan(p);
}
p=p->next;
}
}
}
}
void change(struct address *head)
{
while(1)
{
int temp;
change_cpy(head);
printf("如果你想退出,请输入8;如果你想继续,请输入9:");
scanf("%d",&temp);
if(temp==8)
{
break;
}
}
}
struct address *ins()
{
struct address *p0,*p1,*p2;
if(head==NULL)
{
p0=p1=(struct address * )malloc(LEN);
}
else
{
p1=head;
while(1)
{
p1=p1->next;
if(p1==NULL)
{
p0=p1=(struct address * )malloc(LEN);
break;
}
}
}
printf("请输入要插入的联系人:");
scan(p0);
p1=head;
if(head==NULL)
{
head=p0;
p0->next=NULL;
n=n+1;
return(head);
}
else
{
while((strcmp(p0->name,p1->name)>0)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(head==p1)
{
head=p0;
p0->next=p1;
}
else
{
if(strcmp(p0->name,p2->name)>0&&strcmp(p0->name,p1->name)<0)
{
p2->next=p0;
p0->next=p1;
}
}
if(strcmp(p0->name,p1->name)>=0&&p1->next==NULL)
{
p1->next=p0;
p0->next=NULL;
}
}
n=n+1;
return(head);
}
struct address *del()
{
struct address *p1,*p2;
char good[20];
if(head==NULL)
{
printf("\nlist null\n");
return 0;
}
p1=head;
printf("请输入你想删除的联系人:");
scanf("%s",good);
while((strcmp(good,p1->name)!=0)&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(strcmp(good,p1->name)==0)
{
if(p1==head)
{
head=p1->next;
printf("delete:%s\n",good);
if(head==NULL)
{
return 0;
}
return(head);
}
else
{
p2->next=p1->next;
printf("delete:%s\n",good);
}
n=n-1;
}
else
{
printf("找不到该联系人!");
}
if(head==NULL)
{
return 0;
}
return(head);
}
struct address *sort()
{
struct address *a,*p,*p1,*p2,*p3,*p4;
int f=0,h;
p2=p1=(struct address *)malloc(LEN);
a=(struct address *)malloc(LEN);
p4=p=head;
while(f<n)
{
f=f+1;
if(f==1) head=p1;
else p2->next=p1;
p=p4;
h=0;
while(p!=NULL)
{
h=h+1;
p3=p;
p=p->next;
if(h==1)
{*a=*p3;}
if(strcmp(a->name,p3->name)>0)
{
*a=*p3;
}
}
p=p4;
while(p!=NULL)
{
p3=p;
p=p->next;
if(strcmp(a->name,p4->name)==0)
{
p4=p;
break;
}
if(strcmp(a->name,p->name)==0)
{
p3->next=p->next;
break;
}
}
*p1=*a;
p2=p1;
p1=(struct address *)malloc(LEN);
}
p2->next=NULL;
return head;
}
int main()
{
while(1)
{
switch(menu_select())
{
case 1:add();break;
case 2:look(head);break;
case 3:find(head);break;
case 4:change(head);break;
case 5:ins();break;
case 6:del();break;
case 7:sort();break;
case 8:exit(0);
}
}
return 0;
}