|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
#include <stdlib.h>
|
|
|
struct TXL
|
|
|
{
|
|
|
char XM[20];
|
|
|
char JG[20];
|
|
|
char DHHM1[20];
|
|
|
char DHHM2[20];
|
|
|
char DZYX[20];
|
|
|
char a[20];
|
|
|
char b[20];
|
|
|
char c[20];
|
|
|
char d[20];
|
|
|
char e[20];
|
|
|
};
|
|
|
struct TXL LXR[100];
|
|
|
int num=0,p;
|
|
|
FILE *fp;
|
|
|
|
|
|
void luru()
|
|
|
{
|
|
|
int i;
|
|
|
fp=fopen("D:\\通讯录.txt","a");
|
|
|
for (i=0;i<100;i++)
|
|
|
{
|
|
|
int k;
|
|
|
printf ("输入姓名\n");
|
|
|
scanf ("%s",LXR[num].XM);
|
|
|
printf ("输入籍贯\n");
|
|
|
scanf ("%s",LXR[num].JG);
|
|
|
printf ("输入电话1\n");
|
|
|
scanf ("%s",LXR[num].DHHM1);
|
|
|
printf ("输入电话2\n");
|
|
|
scanf ("%s",LXR[num].DHHM2);
|
|
|
printf("输入电子邮箱\n");
|
|
|
scanf("%s",LXR[num].DZYX);
|
|
|
num++;
|
|
|
p=num;
|
|
|
printf ("是否继续添加(1是0否)");
|
|
|
scanf("%d",&k);
|
|
|
if (k==1)
|
|
|
continue;
|
|
|
|
|
|
else
|
|
|
break;
|
|
|
|
|
|
};
|
|
|
fclose(fp);
|
|
|
}
|
|
|
void liulan ()
|
|
|
{
|
|
|
int a,i=0;
|
|
|
if((fp=fopen("通讯录.txt","r"))==NULL)
|
|
|
printf ("请先录入信息\n");
|
|
|
printf("姓名 籍贯 电话号码1 电话号码2 电子邮箱\n");
|
|
|
while(fscanf(fp,"姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",&LXR[i].XM,&LXR[i].JG,&LXR[i].DHHM1,&LXR[i].DHHM2,&LXR[i].DZYX)!=EOF)
|
|
|
{
|
|
|
printf("%s %s %s %s %s\n",LXR[i].XM,LXR[i].JG,LXR[i].DHHM1,LXR[i].DHHM2,LXR[i].DZYX);
|
|
|
i++;
|
|
|
}
|
|
|
printf ("请按任意字母或数字返回主页面");
|
|
|
scanf("%s",&a);
|
|
|
fclose(fp);
|
|
|
|
|
|
}
|
|
|
void chaxun()
|
|
|
{
|
|
|
int b,n;
|
|
|
char name[20];
|
|
|
int k=0;
|
|
|
if((fp=fopen("通讯录.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("无法打开文件!\n");
|
|
|
return;
|
|
|
}
|
|
|
while(fscanf(fp,"姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",&LXR[k].XM,&LXR[k].JG,&LXR[k].DHHM1,&LXR[k].DHHM2,&LXR[k].DZYX)!=EOF)
|
|
|
{
|
|
|
k++;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
printf ("请输入姓名:\n(如果您输入的信息未录入通讯录本系统将直接提示您返回主页面)\n");
|
|
|
scanf ("%s",&name);
|
|
|
for (n=0;n<k;n++)
|
|
|
{
|
|
|
if (strcmp(LXR[n].XM,name)==0)
|
|
|
{
|
|
|
printf("姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",LXR[n].XM,LXR[n].JG,LXR[n].DHHM1,LXR[n].DHHM2,LXR[n].DZYX);
|
|
|
}
|
|
|
}
|
|
|
printf ("请按任意字母或数字返回主页面");
|
|
|
scanf("%s",&b);
|
|
|
}
|
|
|
void xiugai()
|
|
|
{
|
|
|
int l,v,c;
|
|
|
char xm[20];
|
|
|
int k=0;
|
|
|
if((fp=fopen("通讯录.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("无法打开文件!\n");
|
|
|
return;
|
|
|
}
|
|
|
while(fscanf(fp,"姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",&LXR[k].XM,&LXR[k].JG,&LXR[k].DHHM1,&LXR[k].DHHM2,&LXR[k].DZYX)!=EOF)
|
|
|
{
|
|
|
k++;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
printf ("请输入姓名:\n(如果您输入的信息未录入通讯录本系统将直接提示您返回主页面)\n");
|
|
|
scanf ("%s",&xm);
|
|
|
for (l=0;l<k;l++)
|
|
|
{
|
|
|
if (strcmp(LXR[l].XM,xm)==0)
|
|
|
{
|
|
|
num=l;
|
|
|
printf("姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",LXR[l].XM,LXR[l].JG,LXR[l].DHHM1,LXR[l].DHHM2,LXR[l].DZYX);
|
|
|
printf("请选择您想修改的信息\n1.姓名\n2.籍贯\n3.电话号码1\n4.电话号码2\n5.电子邮箱\n");
|
|
|
scanf("%d",&v);
|
|
|
if(v==1)
|
|
|
{
|
|
|
printf("姓名;%s\n",LXR[l].XM);
|
|
|
printf("请输入修改后的信息\n");
|
|
|
scanf("%s",&LXR[l].a);
|
|
|
strcpy(LXR[num].XM,LXR[l].a);
|
|
|
fp=fopen("通讯录.txt","w");
|
|
|
for(l=0;l<k;l++)
|
|
|
fprintf(fp,"姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",LXR[l].XM,LXR[l].JG,LXR[l].DHHM1,LXR[l].DHHM2,LXR[l].DZYX);
|
|
|
fclose(fp);
|
|
|
}
|
|
|
if(v==2)
|
|
|
{
|
|
|
printf("籍贯:%s\n",LXR[l].JG);
|
|
|
printf("请输入修改后的信息\n");
|
|
|
scanf("%s",&LXR[l].b);
|
|
|
strcpy(LXR[num].JG,LXR[l].b);
|
|
|
fp=fopen("通讯录.txt","w");
|
|
|
for(l=0;l<k;l++)
|
|
|
fprintf(fp,"姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",LXR[l].XM,LXR[l].JG,LXR[l].DHHM1,LXR[l].DHHM2,LXR[l].DZYX);
|
|
|
fclose(fp);
|
|
|
}
|
|
|
if(v==3)
|
|
|
{
|
|
|
printf("电话号码1:%s\n",LXR[l].DHHM1);
|
|
|
printf("请输入修改后的信息\n");
|
|
|
scanf("%s",&LXR[l].c);
|
|
|
strcpy(LXR[num].DHHM1,LXR[l].c);
|
|
|
fp=fopen("通讯录.txt","w");
|
|
|
for(l=0;l<k;l++)
|
|
|
fprintf(fp,"姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",LXR[l].XM,LXR[l].JG,LXR[l].DHHM1,LXR[l].DHHM2,LXR[l].DZYX);
|
|
|
fclose(fp);
|
|
|
}
|
|
|
if(v==4)
|
|
|
{
|
|
|
printf("电话号码2:%s\n",LXR[l].DHHM2);
|
|
|
printf("请输入修改后的信息\n");
|
|
|
scanf("%s",&LXR[l].d);
|
|
|
strcpy(LXR[num].DHHM2,LXR[l].d);
|
|
|
fp=fopen("通讯录.txt","w");
|
|
|
for(l=0;l<k;l++)
|
|
|
fprintf(fp,"姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",LXR[l].XM,LXR[l].JG,LXR[l].DHHM1,LXR[l].DHHM2,LXR[l].DZYX);
|
|
|
fclose(fp);
|
|
|
}
|
|
|
if(v==5)
|
|
|
{
|
|
|
printf("电子邮箱:%s\n",LXR[l].DZYX);
|
|
|
printf("请输入修改后的信息\n");
|
|
|
scanf("%s",&LXR[l].e);
|
|
|
strcpy(LXR[num].DZYX,LXR[l].e);
|
|
|
fp=fopen("通讯录.txt","w");
|
|
|
for(l=0;l<k;l++)
|
|
|
fprintf(fp,"姓名:%s\n籍贯:%s\n电话号码1:%s\n电话号码2:%s\n电子邮箱:%s\n",LXR[l].XM,LXR[l].JG,LXR[l].DHHM1,LXR[l].DHHM2,LXR[l].DZYX);
|
|
|
fclose(fp);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
num=p;
|
|
|
printf ("请按任意字母或数字返回主页面");
|
|
|
scanf("%s",&c);
|
|
|
}
|
|
|
void caidan()
|
|
|
{
|
|
|
int t;
|
|
|
printf("-----------------------通讯录------------------------\n");
|
|
|
printf("| (请输入功能前的数字来选择您想要的服务) |\n");
|
|
|
printf("| 1.信息录入 |\n");
|
|
|
printf("| 2.信息浏览 |\n");
|
|
|
printf("| 3.信息查询 |\n");
|
|
|
printf("| 4.信息修改 |\n");
|
|
|
printf("| 5.退出系统 |\n");
|
|
|
printf("-----------------------------------------------------\n");
|
|
|
scanf("%d",&t);
|
|
|
switch(t)
|
|
|
{
|
|
|
case 1:{
|
|
|
luru();
|
|
|
caidan();
|
|
|
break;
|
|
|
}
|
|
|
case 2:{
|
|
|
liulan();
|
|
|
caidan();
|
|
|
break;
|
|
|
}
|
|
|
case 3:{
|
|
|
chaxun();
|
|
|
caidan();
|
|
|
break;
|
|
|
}
|
|
|
case 4:{
|
|
|
xiugai();
|
|
|
caidan();
|
|
|
break;
|
|
|
}
|
|
|
case 5:
|
|
|
printf("您将退出通讯录\n");
|
|
|
exit(0);
|
|
|
system("cls");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
int main()
|
|
|
{
|
|
|
caidan();
|
|
|
}
|
|
|
|