C语言编写通讯管理系统

任何管理系统的框架都是一样的(增删改查)学会任何一个就可以编写其他管理系统

在编写管理系统前需要熟练使用结构体,指针和数组(结构体指针或结构体数组都可以编写管理系统,本程序为结构体指针)

需要先进行信息录入,每录入一个人的信息点击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;
}









  • 5
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经过本地编译可运行的,下载完成之后配置相应环境即可使用。源码功能都是经过老师肯定的,都能满足要求,有需要放心下载即可。源码是经
#define _CRT_SECURE_NO_WARNINGS 1 #ifndef __CONTACT_H_ #define __CONTACT_H_ #include<stdio.h> #include<stdlib.h> #include<string.h> #define PEO_MAX 30 #define STUID_MAX 10 #define NAME_MAX 20 #define SEX_MAX 10 #define TEL_MAX 15 typedef struct People { char id[STUID_MAX]; char name[NAME_MAX]; char sex[SEX_MAX]; char tel[TEL_MAX]; }*peo; typedef struct Contact { int count; struct People people[PEO_MAX]; }*pCon; void add_peo(pCon pcon); //添加联系人信息 void show_peo(pCon pcon); //显示指定联系人信息 void find_peo(pCon pcon); //查找联系人信息 void modify_peo(pCon pcon); //修改指定联系人信息 void clear_peo(pCon pcon); //清空联系人信息 void show_menu(); //菜单显示 #endif int search(pCon pcon, char *name) { int i = 0; for (i=0; i < pcon->count; i++) { if (strcmp(name, pcon->people[i].name) == 0) return i; } return -1; } void add_peo(pCon pcon) //添加联系人 { if (pcon->count == PEO_MAX) { printf("The contact has fullen."); return; } printf("please input studentID: "); scanf("%s",(pcon->people[pcon->count]).id); printf("please input name: "); scanf("%s", (pcon->people[pcon->count]).name); printf("please input sex : "); scanf("%s", (pcon->people[pcon->count]).sex); printf("please input tel: "); scanf("%s", (pcon->people[pcon->count]).tel); pcon->count++; } void show_peo(pCon pcon)//显示联系人 { int i = 0; for (; i < pcon->count; i++) { printf("studentID name sex tel \n"); printf("%s\t%s\t%s\t%s\n", pcon->people[i].id, pcon->people[i].name, pcon->people[i].sex, pcon->people[i].tel); } } void find_peo(pCon pcon) //查找联系人信息 { int i; char name[NAME_MAX]; printf("please input the people you want to find:"); scanf("%s", name); i = search(pcon, name); if (i == -1) printf("The people doesn't exsit.\n"); else printf("%s\t%s\t%s\t%s\n", pcon->people[i].id, pcon->people[i].name, pcon->people[i].sex, pcon->people[i].tel); } void modify_peo(pCon pcon) //修改指定联系人信息 { int i; char name[NAME_MAX]; printf("please input the people you want to modify:"); scanf("%s", name); i = search(pcon, name); if (i == -1) printf("The people doesn't exsit.\n"); else printf("please input studentID: "); scanf("%s", (pcon->people[i]).id); printf("please input name: "); scanf("%s", (pcon->people[i]).name); printf("please input sex : "); scanf("%s", (pcon->people[i]).sex); printf("please input tel: "); scanf("%s", (pcon->people[i]).tel); } void clear_peo(pCon pcon) //清空联系人 { pcon->count = 0; } void show_menu() //菜单显示 { printf("==========通讯录==========\n"); printf(" \n"); printf("*******[1]显示通讯录******\n"); printf("*******[2]查 询******\n"); printf("*******[3]修 改******\n"); printf("*******[4]结 束******\n"); } int main() { struct Contact my_contact; int input = 1; my_contact.count = 0; while (input) { show_menu(); printf("please input:"); scanf("%d", &input;); switch (input) { case 1: add_peo(&my;_contact); break; case 2: show_peo(&my;_contact); break; case 3: find_peo(&my;_contact); break; case 4: modify_peo(&my;_contact); break; case 5: clear_peo(&my;_contact); break; default: break; } } return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值