|
|
@ -0,0 +1,485 @@
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
|
|
|
#include<string.h>
|
|
|
|
|
|
|
|
#include<conio.h>//为了使用gitch函数,调用此头文件
|
|
|
|
|
|
|
|
#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];//联系人的电话号码1
|
|
|
|
|
|
|
|
char tel_2[15];//联系人的电话号码2
|
|
|
|
|
|
|
|
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)//当n=0时退出菜单,结束程序
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch(n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
addman();//当n=1时,进入添加联系人模块
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
queryman();//当n=1时,进入添加联系人模块
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
delman();//当n=1时,进入添加联系人模块
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
update();//当n=1时,进入添加联系人模块
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
outputman();//当n=1时,进入添加联系人模块
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
menu();//各功能运行完break之后 又进入菜单界面,直到退出
|
|
|
|
|
|
|
|
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))//检测流上的文件结束符 即文件结束:返回非0值。文件未结束:返回0值)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(fread(&peo[count],Bytes,1,p1)==1) //从文件流中读数据,如果不成功或读到文件末尾 ,则返回 0
|
|
|
|
|
|
|
|
count++; //如果成功读取了 一次 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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("\n\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);
|
|
|
|
|
|
|
|
printf("\n\t%s 添加成功!\n",peo[count].name);
|
|
|
|
|
|
|
|
count++; //联系人数目加一
|
|
|
|
|
|
|
|
n=0;//输入完毕后退出添加联系人功能
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<count;i++) fwrite(&peo[i],Bytes,1,p1);//循环重新全部写入文件
|
|
|
|
|
|
|
|
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))//检测流上的文件结束符 即文件结束:返回非0值。文件未结束:返回0值)
|
|
|
|
|
|
|
|
if(fread(&peo[count],Bytes,1,p1)) //将文件中的数据读到结构体中
|
|
|
|
|
|
|
|
count++;//读取成功一次 联系人数量加一
|
|
|
|
|
|
|
|
fclose(p1); //读取后关闭文件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(count==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("联系人列表为空!\n");
|
|
|
|
|
|
|
|
printf("请按任意键继续");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(n)// n变量为是否继续查询的判断条件 所以先初始化n=1
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
outputman();//先输出联系人列表
|
|
|
|
|
|
|
|
while(flag!=0)//flag为是否继续查询 当选择返回时 令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)//当循环到最后一个时还没有找到要查询的人,执行该if语句
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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)//查询电话号码2
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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))//检测流上的文件结束符 即文件结束:返回非0值。文件未结束:返回0值)
|
|
|
|
|
|
|
|
if(fread(&peo[count],Bytes,1,p1)==1) //将文件中的数据读到结构体中
|
|
|
|
|
|
|
|
count++;//每成功读取一次联系人数量加一
|
|
|
|
|
|
|
|
fclose(p1); //关闭文件
|
|
|
|
|
|
|
|
if(count==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\t\t联系人列表为空!\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(j==1)//j变量为判断是否继续修改的判断条件
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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)// n量为判断是否修改的判断条件
|
|
|
|
|
|
|
|
{ j=0;//如果不修改就退出修改功能
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while(n==1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
while(flag==1)//flag变量为判断是否修改其他信息的判断条件
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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)//修改电话号码1
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n\t\t请输入要修改的信息:");
|
|
|
|
|
|
|
|
scanf("%s",&peo[i].tel_1);
|
|
|
|
|
|
|
|
printf("\n\t\t修改成功!\n");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m==4)//修改电话号码2
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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;//退出修改功能
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(flag==0)break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(i==count)// 当循环到最后一个时还没有找到要查询的人,执行该if语句
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n\t\t\t该联系人不存在!\n\t\t\t请按任意键重新输入");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
outputman;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}//然后继续选择要修改的人
|
|
|
|
|
|
|
|
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) //m为是否继续删除的判断条件
|
|
|
|
|
|
|
|
{ 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)//k为是否删除改联系人的判断条件
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|