You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
5.6 KiB
258 lines
5.6 KiB
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
typedef struct
|
|
{
|
|
char name[10];
|
|
char jiguan[20];
|
|
long long num1;
|
|
long long num2;
|
|
char email[20];
|
|
}person;
|
|
void xinjian(FILE *p);
|
|
void liulan(FILE *p);
|
|
void chaxun(FILE *p);
|
|
void xiugai(FILE *p);
|
|
int shanchu(FILE *p);
|
|
int count=0;
|
|
FILE *p;
|
|
person lxr;
|
|
void main()
|
|
{
|
|
char next='Y';
|
|
char ch;
|
|
int b;
|
|
while(next=='Y')
|
|
{
|
|
printf("---------欢迎使用讯通讯录---------\n");
|
|
printf("功能目录:\n");
|
|
printf("1:新建联系人\n");
|
|
printf("2:查看联系人\n");
|
|
printf("3:查找联系人\n");
|
|
printf("4:修改联系人信息\n");
|
|
printf("5:删除联系人\n");
|
|
printf("6:退出通讯录\n");
|
|
int c;
|
|
printf("请输入序号:");
|
|
scanf("%d",&c);
|
|
switch(c)
|
|
{
|
|
case 1:xinjian(p);
|
|
break;
|
|
case 2:liulan(p);
|
|
break;
|
|
case 3:chaxun(p);
|
|
break;
|
|
case 4:xiugai(p);
|
|
break;
|
|
case 5:b=shanchu(p);
|
|
break;
|
|
case 6:printf("感谢您的使用");
|
|
break;
|
|
default:printf("请输入正确的序号:\n");
|
|
break;
|
|
}
|
|
if(c==6)
|
|
next='N';
|
|
else
|
|
{
|
|
printf("继续使用系统功能:Y\n退出:其他字母\n");
|
|
if(c==5)
|
|
scanf("%c",&next);
|
|
else
|
|
scanf("%c%c",&ch,&next);
|
|
}
|
|
}
|
|
}
|
|
void xinjian(FILE *p)
|
|
{
|
|
char next='Y';
|
|
p=fopen("txl.sto","rb+");
|
|
if(p==NULL)
|
|
p=fopen("txl.sto","wb+");
|
|
fseek(p,0,SEEK_END);
|
|
while(next=='Y')
|
|
{
|
|
printf("姓名:\n");
|
|
scanf("%s",lxr.name);
|
|
printf("籍贯:\n");
|
|
scanf("%s",lxr.jiguan);
|
|
printf("电话号码1:\n");
|
|
scanf("%lld",&lxr.num1);
|
|
printf("电话号码2:\n");
|
|
scanf("%lld",&lxr.num2);
|
|
printf("邮箱:\n");
|
|
scanf("%s",lxr.email);
|
|
fwrite(&lxr,sizeof(lxr),1,p);
|
|
fflush(stdin);
|
|
printf("是否继续进行建立新联系人;\n是:Y\n否:其他字母\n");
|
|
next=getchar();
|
|
count=count+1;
|
|
}
|
|
fclose(p);
|
|
|
|
|
|
}
|
|
void liulan(FILE *p)
|
|
{ int i=0;
|
|
p=fopen("txl.sto","rb+");
|
|
if(p==NULL)
|
|
{
|
|
printf("通讯录为空,请建立新联系人!\n");
|
|
fclose(p);
|
|
}
|
|
else
|
|
{
|
|
rewind(p);
|
|
printf("\n\nItem list-------------------------------------1\n");
|
|
printf("姓名 籍贯 电话号码1 电话号码2 邮箱\n");
|
|
fread(&lxr,sizeof(lxr),1,p);
|
|
while(!feof(p))
|
|
{
|
|
printf("%s %s %lld %lld %s\n",lxr.name,lxr.jiguan,lxr.num1,lxr.num2,lxr.email);
|
|
fread(&lxr,sizeof(lxr),1,p);
|
|
}
|
|
fclose(p);
|
|
}
|
|
|
|
}
|
|
void chaxun(FILE *p)
|
|
{
|
|
int i=0;
|
|
p=fopen("txl.sto","rb+");
|
|
if(p==NULL)
|
|
{
|
|
printf("通讯录为空,请建立新联系人!\n");
|
|
fclose(p);
|
|
}
|
|
else
|
|
{
|
|
char mingzi[20];
|
|
printf("请输入要查询的用户名:\n");
|
|
scanf("%s",mingzi);
|
|
fread(&lxr,sizeof(lxr),1,p);
|
|
while(!feof(p))
|
|
{
|
|
if(strcmp(mingzi,lxr.name)==0)
|
|
{
|
|
printf("姓名: 籍贯: 电话号码1: 电话号码2: 邮箱:\n");
|
|
printf("%s %s %lld %lld %s\n",lxr.name,lxr.jiguan,lxr.num1,lxr.num2,lxr.email);
|
|
i=i+1;
|
|
}
|
|
|
|
fread(&lxr,sizeof(lxr),1,p);
|
|
}
|
|
if(i==count&&(strcmp(mingzi,lxr.name)!=0))
|
|
printf("无该联系人\n");
|
|
fclose(p);
|
|
}
|
|
}
|
|
void xiugai(FILE *p)
|
|
{
|
|
rewind(p);
|
|
p=fopen("txl.sto","rb+");
|
|
if(p==NULL)
|
|
{
|
|
printf("通讯录为空,请建立新联系人!\n");
|
|
fclose(p);
|
|
}
|
|
else
|
|
{
|
|
char mingzi[20];
|
|
printf("请输入要修改的有用户名:\n");
|
|
scanf("%s",mingzi);
|
|
while(!feof(p))
|
|
{
|
|
fread(&lxr,sizeof(lxr),1,p);
|
|
if(strcmp(mingzi,lxr.name)==0)
|
|
{
|
|
char next='Y';
|
|
printf("1.姓名:%s\n",lxr.name);
|
|
printf("2.籍贯:%s\n",lxr.jiguan);
|
|
printf("3.电话号码1:%lld\n",lxr.num1);
|
|
printf("4.电话号码2:%lld\n",lxr.num2);
|
|
printf("5.邮箱:%s\n",lxr.email);
|
|
printf("6.取消\n");
|
|
while(next=='Y')
|
|
{
|
|
int c;
|
|
printf("请输入序号:");
|
|
scanf("%d",&c);
|
|
switch(c)
|
|
{
|
|
case 1:printf("请修改姓名:");
|
|
scanf("%s",lxr.name);
|
|
break;
|
|
case 2:printf("请修改籍贯:");
|
|
scanf("%s",lxr.jiguan);
|
|
break;
|
|
case 3:printf("请修改电话号码1:");
|
|
scanf("%s",lxr.num1);
|
|
break;
|
|
case 4:printf("请修改电话号码2:");
|
|
scanf("%s",lxr.num2);
|
|
break;
|
|
case 5:printf("请修改邮箱:");
|
|
scanf("%s",lxr.email);
|
|
break;
|
|
default:printf("输入错误");
|
|
break;
|
|
}
|
|
printf("继续修改:Y\n停止修改:其他字母\n");
|
|
getchar();
|
|
next=getchar();
|
|
}
|
|
fseek(p,-sizeof(lxr),SEEK_CUR);
|
|
fwrite(&lxr,sizeof(lxr),1,p);
|
|
printf("修改成功!\n");
|
|
fclose(p);
|
|
return ;
|
|
}
|
|
|
|
|
|
}
|
|
printf("没有该联系人\n");
|
|
fclose(p);
|
|
return;
|
|
}
|
|
}
|
|
int shanchu(FILE *p)
|
|
{
|
|
p=fopen("txl.sto","rb+");
|
|
if(p==NULL)
|
|
{
|
|
printf("通讯录为空,请建立新联系人!\n");
|
|
fclose(p);
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
person b;
|
|
person blank={};
|
|
char name[20];
|
|
int c=0;
|
|
rewind(p);
|
|
printf("请输入您要删除的联系人名称:");
|
|
scanf("%s",name);
|
|
fflush(stdin);
|
|
while(!feof(p))
|
|
{
|
|
fread(&b,sizeof(b),1,p);
|
|
if(strcmp(name,b.name)==0)
|
|
{
|
|
fseek(p,-sizeof(b),SEEK_CUR);
|
|
fwrite(&blank,sizeof(blank),1,p);
|
|
printf("删除成功!\n");
|
|
fclose(p);
|
|
c=c+1;
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
if(c==count&&(strcmp(name,b.name)!=0))
|
|
printf("无该联系人!\n");
|
|
fclose(p);
|
|
return 0;
|
|
}
|
|
}
|