|
|
|
@ -0,0 +1,486 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
#include<conio.h>
|
|
|
|
|
#include<dos.h>
|
|
|
|
|
#define Bytes sizeof(struct linkman) //宏定义
|
|
|
|
|
#define FORMAT "\t%-10s%-10s%-15s%-15s%-20s\n\n" //宏定义输出格式
|
|
|
|
|
#define DATA peo[i].name,peo[i].birthplace,peo[i].tel_1,peo[i].tel_2,peo[i].email //宏定义结构体输出列表
|
|
|
|
|
struct linkman
|
|
|
|
|
{
|
|
|
|
|
char name[10];
|
|
|
|
|
char birthplace[10];
|
|
|
|
|
char tel_1[15];
|
|
|
|
|
char tel_2[15];
|
|
|
|
|
char email[20];
|
|
|
|
|
};
|
|
|
|
|
struct linkman peo[100];
|
|
|
|
|
void addman();
|
|
|
|
|
void queryman();
|
|
|
|
|
void delman();
|
|
|
|
|
void update();
|
|
|
|
|
void outputman();
|
|
|
|
|
void menu();
|
|
|
|
|
|
|
|
|
|
void menu()//菜单模块
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("\n\t\t**********通讯录管理系统*********\n");
|
|
|
|
|
printf("\t\t┌-------------------------------┐\n");
|
|
|
|
|
printf("\t\t│ 1.添加联系人 │\n");
|
|
|
|
|
printf("\t\t│ 2.查询联系人 │\n");
|
|
|
|
|
printf("\t\t│ 3.删除联系人 │\n");
|
|
|
|
|
printf("\t\t│ 4.修改联系人信息 │\n");
|
|
|
|
|
printf("\t\t│ 5.输出联系人列表 │\n");
|
|
|
|
|
printf("\t\t│ 0.退出 │\n");
|
|
|
|
|
printf("\t\t└-------------------------------┘\n");
|
|
|
|
|
printf("\t\t请您选择功能(0-5):");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tou() //列表头
|
|
|
|
|
{ system("cls");
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf("*************************************联系人列表***************************************\n\n");
|
|
|
|
|
printf("\t姓名\t 籍贯\t 电话号码1\t 电话号码2\t 电子邮箱\n\n");
|
|
|
|
|
}
|
|
|
|
|
void wei() //列表尾
|
|
|
|
|
{
|
|
|
|
|
printf("\n**************************************************************************************\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
|
{
|
|
|
|
|
system("mode con: cols=86 lines=30");//设置窗口大小
|
|
|
|
|
int n;
|
|
|
|
|
menu();
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
while(n)
|
|
|
|
|
{
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
addman();
|
|
|
|
|
getch();
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
queryman();
|
|
|
|
|
getch();
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
delman();
|
|
|
|
|
getch();
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
update();
|
|
|
|
|
getch();
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
outputman();
|
|
|
|
|
getch();
|
|
|
|
|
break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
menu();
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void addman()
|
|
|
|
|
{
|
|
|
|
|
FILE *p1;
|
|
|
|
|
int i,n,count=0; // count为联系人个数
|
|
|
|
|
if ((p1=fopen("D:\\我的项目\\linkman.txt","a+"))==NULL) //打开linkman文件
|
|
|
|
|
{
|
|
|
|
|
printf("不能打开此文件");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(!feof(p1)) //feof为检测文件结束符
|
|
|
|
|
{
|
|
|
|
|
if(fread(&peo[count],Bytes,1,p1)==1)
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
fclose(p1); //关闭文件
|
|
|
|
|
if(count==0)
|
|
|
|
|
printf("\n\t联系人列表为空!\n\n");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
system("cls"); //清屏
|
|
|
|
|
outputman();
|
|
|
|
|
}
|
|
|
|
|
if ((p1=fopen("D:\\我的项目\\linkman.txt","wb"))==NULL)//以二进制方式打开linkman文件
|
|
|
|
|
{
|
|
|
|
|
printf("\t不能打开联系人列表\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(i=0;i<count;i++)
|
|
|
|
|
fwrite(&peo[i],Bytes,1,p1);
|
|
|
|
|
|
|
|
|
|
printf("\t是否添加联系人(1 or 0):");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
while(n==1)
|
|
|
|
|
{
|
|
|
|
|
printf("\t请输入信息:\n\n");
|
|
|
|
|
printf("\t姓名: ");//输入姓名
|
|
|
|
|
scanf("%s",&peo[count].name);
|
|
|
|
|
|
|
|
|
|
for(i=0;i<count;i++)//该联系人是否已经存在
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(peo[i].name,peo[count].name)==0)
|
|
|
|
|
{
|
|
|
|
|
printf("\t该联系人已存在!\n");
|
|
|
|
|
getch();
|
|
|
|
|
fclose(p1); //关闭文件
|
|
|
|
|
return; //重新输入联系人
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("\n\t籍贯: "); //输入籍贯
|
|
|
|
|
scanf("%s",&peo[count].birthplace);
|
|
|
|
|
printf("\n\t电话号码1: "); //输入number1
|
|
|
|
|
scanf("%s",&peo[count].tel_1);
|
|
|
|
|
printf("\n\t电话号码2: "); //输入number2
|
|
|
|
|
scanf("%s",&peo[count].tel_2);
|
|
|
|
|
printf("\n\t电子邮箱: "); //输入邮箱
|
|
|
|
|
scanf("%s",&peo[count].email);
|
|
|
|
|
fwrite(&peo[count],Bytes,1,p1);
|
|
|
|
|
printf("\n\t%s 添加成功!\n",peo[count].name);
|
|
|
|
|
count++; //联系人数目加一
|
|
|
|
|
n=0;
|
|
|
|
|
}
|
|
|
|
|
fclose(p1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void queryman()
|
|
|
|
|
{
|
|
|
|
|
FILE *p1;
|
|
|
|
|
int i,n=1,m,count=0,flag=1;
|
|
|
|
|
|
|
|
|
|
if ((p1=fopen("D:\\我的项目\\linkman.txt","rb"))==NULL)//以二进制方式打开linkman文件
|
|
|
|
|
exit(0);
|
|
|
|
|
while(!feof(p1))//判断是否到达文件尾部
|
|
|
|
|
if(fread(&peo[count],Bytes,1,p1)) //将文件中的数据读到结构体中
|
|
|
|
|
count++;
|
|
|
|
|
fclose(p1);
|
|
|
|
|
|
|
|
|
|
if(count==0)
|
|
|
|
|
{
|
|
|
|
|
printf("联系人列表为空!\n");
|
|
|
|
|
printf("请按任意键继续");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(n)
|
|
|
|
|
{
|
|
|
|
|
outputman();
|
|
|
|
|
while(flag!=0)
|
|
|
|
|
{ system("cls");//清屏
|
|
|
|
|
printf("\n\t\t**********查询方式***********\n");
|
|
|
|
|
printf("\t\t┌-------------------------------┐\n");
|
|
|
|
|
printf("\t\t│ 1.姓名 │\n");
|
|
|
|
|
printf("\t\t│ 2.籍贯 │\n");
|
|
|
|
|
printf("\t\t│ 3.手机号码1 │\n");
|
|
|
|
|
printf("\t\t│ 4.查找手机号码2 │\n");
|
|
|
|
|
printf("\t\t│ 5.电子邮箱 │\n");
|
|
|
|
|
printf("\t\t│ 0.返回 │\n");
|
|
|
|
|
printf("\t\t└-------------------------------┘\n");
|
|
|
|
|
printf("\n\t\t请选择查询方式:");
|
|
|
|
|
scanf("\t\t%d",&m);//选择查询式
|
|
|
|
|
|
|
|
|
|
if(m==1)
|
|
|
|
|
{
|
|
|
|
|
char name[15];
|
|
|
|
|
printf("\t\t请输入名字:");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
for(i=0;i<=count;++i)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(name,peo[i].name)==0)
|
|
|
|
|
{ tou();
|
|
|
|
|
printf(FORMAT,DATA);
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
if(count==i)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t\t该联系人不存在!\n\t\t\t请按任意键重新输入");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m==2)
|
|
|
|
|
{
|
|
|
|
|
char bp[15];
|
|
|
|
|
printf("\t\t请输入籍贯:");
|
|
|
|
|
scanf("%s",bp);
|
|
|
|
|
for(i=0;i<=count;i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(bp,peo[i].birthplace)==0)
|
|
|
|
|
{ tou();
|
|
|
|
|
printf(FORMAT,DATA);
|
|
|
|
|
}
|
|
|
|
|
if(count==i)
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t\t该联系人不存在!\n\t\t\t请按任意键重新输入");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m==3)
|
|
|
|
|
{
|
|
|
|
|
char num1[15];
|
|
|
|
|
printf("\t\t请输入电话号码:");
|
|
|
|
|
scanf("%s",num1);
|
|
|
|
|
for(i=0;i<=count;i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(num1,peo[i].tel_1)==0)
|
|
|
|
|
{ tou();
|
|
|
|
|
printf(FORMAT,DATA);
|
|
|
|
|
}
|
|
|
|
|
if(count==i)
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t\t该联系人不存在!\n\t\t\t请按任意键重新输入");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m==4)
|
|
|
|
|
{
|
|
|
|
|
char num2[15];
|
|
|
|
|
printf("\t\t请输入电话号码:");
|
|
|
|
|
scanf("%s",num2);
|
|
|
|
|
for(i=0;i<=count;i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(num2,peo[i].tel_2)==0)
|
|
|
|
|
{ tou();
|
|
|
|
|
printf(FORMAT,DATA);
|
|
|
|
|
}
|
|
|
|
|
if(count==i)
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t\t该联系人不存在!\n\t\t\t请按任意键重新输入");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m==5)
|
|
|
|
|
{
|
|
|
|
|
char mail[20];
|
|
|
|
|
printf("\t\t请输入邮箱地址:");
|
|
|
|
|
scanf("%s",mail);
|
|
|
|
|
for(i=0;i<=count;i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(mail,peo[i].email)==0)
|
|
|
|
|
{ tou();
|
|
|
|
|
printf(FORMAT,DATA);
|
|
|
|
|
}
|
|
|
|
|
if(count==i)
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t\t该联系人不存在!\n\t\t\t请按任意键重新输入");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m==0)
|
|
|
|
|
{
|
|
|
|
|
flag=0;
|
|
|
|
|
n=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void update() //修改联系人函数模块
|
|
|
|
|
{
|
|
|
|
|
FILE *p1;
|
|
|
|
|
int i,m,n;
|
|
|
|
|
int flag=1,count=0,j=1;
|
|
|
|
|
char name[15];
|
|
|
|
|
if ((p1=fopen("D:\\我的项目\\linkman.txt","r+"))==NULL)//以二进制方式打开linkman文件
|
|
|
|
|
exit(0);
|
|
|
|
|
while(!feof(p1))//判断是否到达文件尾部
|
|
|
|
|
if(fread(&peo[count],Bytes,1,p1)==1) //将文件中的数据读到结构体中
|
|
|
|
|
count++;
|
|
|
|
|
fclose(p1); //关闭文件
|
|
|
|
|
if(count==0)
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t联系人列表为空!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(j==1)
|
|
|
|
|
{
|
|
|
|
|
outputman();
|
|
|
|
|
printf("请输入想要修改的联系人的名字:");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
for(i=0;i<=count;i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(name,peo[i].name)==0)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t已找到联系人!\n\n");
|
|
|
|
|
printf("\t\t是否修改?(1 or 0):");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
if(n==0)
|
|
|
|
|
{ j=0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
while(n==1)
|
|
|
|
|
{
|
|
|
|
|
while(flag==1)
|
|
|
|
|
{
|
|
|
|
|
system("cls");//清屏
|
|
|
|
|
printf("\n\t\t************选择修改项************\n");
|
|
|
|
|
printf("\t\t┌-------------------------------┐\n");
|
|
|
|
|
printf("\t\t│ 1.修改姓名 │\n");
|
|
|
|
|
printf("\t\t│ 2.修改籍贯 │\n");
|
|
|
|
|
printf("\t\t│ 3.修改手机号码1 │\n");
|
|
|
|
|
printf("\t\t│ 4.查找手机号码2 │\n");
|
|
|
|
|
printf("\t\t│ 5.修改电子邮箱 │\n");
|
|
|
|
|
printf("\t\t│ 0.返回 │\n");
|
|
|
|
|
printf("\t\t└-------------------------------┘\n");
|
|
|
|
|
printf("\n\t请选择功能前的数字:");
|
|
|
|
|
scanf("%d",&m);//选择修改方式
|
|
|
|
|
if(m==1)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t请输入要修改的信息:");
|
|
|
|
|
scanf("%s",&peo[i].name);
|
|
|
|
|
printf("\n\t\t修改成功!\n");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
if(m==2)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t请输入要修改的信息:");
|
|
|
|
|
scanf("%s",&peo[i].birthplace);
|
|
|
|
|
printf("\n\n\t\t修改成功!\n");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
if(m==3)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t请输入要修改的信息:");
|
|
|
|
|
scanf("%s",&peo[i].tel_1);
|
|
|
|
|
printf("\n\t\t修改成功!\n");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
if(m==4)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t请输入要修改的信息:");
|
|
|
|
|
scanf("%s",&peo[i].tel_2);
|
|
|
|
|
printf("\n\t\t修改成功!\n");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
if(m==5)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t请输入要修改的信息:");
|
|
|
|
|
scanf("%s",&peo[i].email);
|
|
|
|
|
printf("\n\t\t修改成功!\n");
|
|
|
|
|
getch();
|
|
|
|
|
}
|
|
|
|
|
if(m==0)
|
|
|
|
|
{
|
|
|
|
|
n=0;//退出修改功能
|
|
|
|
|
}
|
|
|
|
|
printf("\n\t\t退出还是继续修改?(1 or 0):");
|
|
|
|
|
scanf("%d",&flag);
|
|
|
|
|
if(flag==0) n=0,j=0;return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(i==count)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t\t该联系人不存在!\n\t\t\t请按任意键重新输入");
|
|
|
|
|
getch();
|
|
|
|
|
i=count+1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if((p1=fopen("D:\\我的项目\\linkman.txt","wb"))==NULL)
|
|
|
|
|
return;
|
|
|
|
|
for(i=0;i<count;i++)
|
|
|
|
|
fwrite(&peo[i],Bytes,1,p1);
|
|
|
|
|
fclose(p1);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void delman()
|
|
|
|
|
{
|
|
|
|
|
FILE *p1;
|
|
|
|
|
int i,j,m=1,k=1,count=0;
|
|
|
|
|
char name[15];
|
|
|
|
|
if((p1=fopen("D:\\我的项目\\linkman.txt","r+"))==NULL)
|
|
|
|
|
return;
|
|
|
|
|
while(!feof(p1))
|
|
|
|
|
if(fread(&peo[count],Bytes,1,p1)==1)
|
|
|
|
|
count++;
|
|
|
|
|
fclose(p1);
|
|
|
|
|
if(count==0)
|
|
|
|
|
{
|
|
|
|
|
printf("联系人列表为空");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
outputman();
|
|
|
|
|
while(m==1)
|
|
|
|
|
{ system("cls");
|
|
|
|
|
outputman();
|
|
|
|
|
printf("\t\t请输入想要删除的联系人的名字:");
|
|
|
|
|
scanf("%s",&name);
|
|
|
|
|
for(i=0;i<=count;++i)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(name,peo[i].name)==0)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t\t已找到该联系人!\n\n\t\t\t是否删除(0 or 1):");
|
|
|
|
|
scanf("%d",&k);
|
|
|
|
|
if(k==1)
|
|
|
|
|
{
|
|
|
|
|
for(j=i;j<count;j++)
|
|
|
|
|
peo[j]=peo[j+1];
|
|
|
|
|
count--;
|
|
|
|
|
if((p1=fopen("D:\\我的项目\\linkman.txt","wb"))==NULL)
|
|
|
|
|
return;
|
|
|
|
|
for(j=0;j<count;j++)
|
|
|
|
|
fwrite(&peo[j],Bytes,1,p1);
|
|
|
|
|
fclose(p1);
|
|
|
|
|
printf("\n\t\t\t删除成功!");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
if(k==0) break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(i==count)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t\t该联系人不存在!\n\t\t\t请按任意键重新输入");
|
|
|
|
|
getch();
|
|
|
|
|
system("cls");
|
|
|
|
|
outputman();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void outputman()
|
|
|
|
|
{
|
|
|
|
|
FILE *p1;
|
|
|
|
|
int i,count=0;
|
|
|
|
|
if ((p1=fopen("D:\\我的项目\\linkman.txt","rb"))==NULL)//以二进制方式打开linkman文件
|
|
|
|
|
exit(0);
|
|
|
|
|
while(!feof(p1))//判断是否到达文件尾部
|
|
|
|
|
if(fread(&peo[count],Bytes,1,p1)==1) //将文件中的数据读到结构体中
|
|
|
|
|
count++;
|
|
|
|
|
fclose(p1);
|
|
|
|
|
tou();
|
|
|
|
|
for(i=0;i<count;i++)
|
|
|
|
|
printf(FORMAT,DATA);
|
|
|
|
|
wei();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|