|
|
#include<stdio.h>
|
|
|
#include<stdlib.h>
|
|
|
#include<string.h>
|
|
|
#include<conio.h>
|
|
|
#include<dos.h>
|
|
|
#define LEN 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=75 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],LEN,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],LEN,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],LEN,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],LEN,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() //修改联系人函数模块
|
|
|
{
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void delman()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
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],LEN,1,p1)==1) //将文件中的数据读到结构体中
|
|
|
count++;
|
|
|
fclose(p1);
|
|
|
tou();
|
|
|
for(i=0;i<count;i++)
|
|
|
printf(FORMAT,DATA);
|
|
|
wei();
|
|
|
}
|
|
|
|
|
|
|
|
|
|