|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
#include <conio.h>
|
|
|
struct record
|
|
|
{
|
|
|
char nativeplace[20];
|
|
|
char name[20];
|
|
|
char phone1[20];
|
|
|
char phone2[20];
|
|
|
char e_mail[30];
|
|
|
}student[500];
|
|
|
int num=0;//外部变量num为文件中的纪录数
|
|
|
FILE *fp;
|
|
|
void welcome(); //欢迎
|
|
|
void mainmenu(); //主菜单
|
|
|
void newrecord(); //新添纪录
|
|
|
void modify(); //修改联系人
|
|
|
void modifyname(); //姓名修改
|
|
|
void modifyphone1(); //电话号码1修改
|
|
|
void modifyphone2(); //电话号码2修改
|
|
|
void searchmenu(); //查询菜单
|
|
|
void searchbynativeplace(); //按籍贯查询
|
|
|
void searchbyname(); //按姓名查询
|
|
|
void searchbyphone1(); //按电话1查询
|
|
|
void searchbyphone2(); //按电话2查询
|
|
|
void deletemenu(); //删除菜单
|
|
|
void deleteall(); //删除所有
|
|
|
void deleteone(); //删除单个
|
|
|
void showall(); //显示所有
|
|
|
void readfromfile(); //读取文件
|
|
|
void writetofile(); //写入文件
|
|
|
void deletebynativeplace(); //按籍贯删除
|
|
|
void deletebyname(); //按姓名删除
|
|
|
void listbynativeplace(); //按籍贯排序
|
|
|
void listbyname(); //按姓名排序
|
|
|
void listmenu(); //排序菜单
|
|
|
int main() //主函数
|
|
|
{
|
|
|
welcome();
|
|
|
readfromfile();
|
|
|
while (1)
|
|
|
{
|
|
|
mainmenu();
|
|
|
}
|
|
|
}
|
|
|
void welcome()//欢迎界面
|
|
|
{
|
|
|
printf("\n\n\n\n\n\n");
|
|
|
printf("\t\t\t============通讯录程序设计==============\n");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t 欢迎使用! \n");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t===============按任意键=================\n");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
void writetofile()//写入文件
|
|
|
{
|
|
|
int i;
|
|
|
if ((fp=fopen("student.bin","wb"))==NULL)
|
|
|
{
|
|
|
printf("\n\t\t文件打开失败");
|
|
|
}
|
|
|
for (i=0;i<num;i++)
|
|
|
{
|
|
|
if (fwrite(&student[i],sizeof(struct record),1,fp)!=1)
|
|
|
{
|
|
|
printf("\n\t\t写入文件错误!\n");
|
|
|
}
|
|
|
}
|
|
|
fclose(fp);
|
|
|
printf("\n\t\t通讯录文件已保存");
|
|
|
printf("\n\t\t按任意键退出程序\n\t\t");
|
|
|
exit(0);
|
|
|
}
|
|
|
void readfromfile()//从文件导入
|
|
|
{
|
|
|
system("cls");
|
|
|
if((fp=fopen("student.bin","rb"))==NULL)
|
|
|
{
|
|
|
printf("\n\t\t通讯录文件不存在");
|
|
|
if ((fp=fopen("student.bin","wb"))==NULL)
|
|
|
{
|
|
|
printf("\n\t\t建立失败");
|
|
|
exit(0);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("\n\t\t通讯录文件已建立");
|
|
|
printf("\n\t\t按任意键进入主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
exit(0);
|
|
|
}
|
|
|
fseek(fp,0,2); /*文件位置指针移动到文件末尾*/
|
|
|
if (ftell(fp)>0) /*文件不为空*/
|
|
|
{
|
|
|
rewind(fp); /*文件位置指针移动到文件开始位置*/
|
|
|
for (num=0;!feof(fp) && fread(&student[num],sizeof(struct record),1,fp);num++);
|
|
|
printf("\n\t\t文件导入成功");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
printf("\n\t\t文件导入成功");
|
|
|
printf("\n\t\t通讯录文件中无任何纪录");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}//文件导入完毕
|
|
|
void mainmenu()//主菜单
|
|
|
{
|
|
|
char choic;
|
|
|
system("cls");
|
|
|
printf("\n\t\t******************* 主菜单 ********************");
|
|
|
printf("\n\t\t********** 1-新添记录 2-修改记录 *************");
|
|
|
printf("\n\t\t********** 3-查询菜单 4-删除记录 *************");
|
|
|
printf("\n\t\t********** 5-记录排序 6-保存退出 *************");
|
|
|
printf("\n\t\t********** 7-不保存退出 *************");
|
|
|
printf("\n\t\t************************************************");
|
|
|
printf("\n\t\t请选择:");
|
|
|
choic=getch();
|
|
|
switch (choic)
|
|
|
{
|
|
|
case '1':newrecord();break;
|
|
|
case '2':modify();break;
|
|
|
case '3':searchmenu();break;
|
|
|
case '4':deletemenu();break;
|
|
|
case '5':listmenu();break;
|
|
|
case '6':writetofile();break;
|
|
|
case '7':exit(0);
|
|
|
default:mainmenu();
|
|
|
}
|
|
|
}
|
|
|
void newrecord()//添加记录
|
|
|
{
|
|
|
printf("\n\t\t**************** 请输入联系人信息 ****************\n");
|
|
|
printf("\n\t\t输入籍贯:");
|
|
|
scanf("%s",&student[num].nativeplace);
|
|
|
printf("\n\t\t输入姓名:");
|
|
|
scanf("%s",&student[num].name);
|
|
|
printf("\n\t\t输入电话号码1:");
|
|
|
scanf("%s",&student[num].phone1);
|
|
|
printf("\n\t\t输入电话号码2:");
|
|
|
scanf("%s",&student[num].phone2);
|
|
|
printf("\n\t\t输入e-mail:");
|
|
|
scanf("%s",&student[num].e_mail);
|
|
|
num++;/*统计联系人个数*/
|
|
|
printf("\n\t\t是否继续添加?(Y/N):");
|
|
|
if (getch()=='y')
|
|
|
newrecord();
|
|
|
return;
|
|
|
}//结束添加新联系人
|
|
|
|
|
|
void deletemenu()//删除菜单
|
|
|
{
|
|
|
char choic;
|
|
|
if(num==0)
|
|
|
{
|
|
|
printf("\n\t\t对不起,文件中无任何纪录");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
system("cls");
|
|
|
printf("\n\t\t******************* 删除菜单 *******************");
|
|
|
printf("\n\t\t*********** 1-删除所有 2-删除单个 ***********");
|
|
|
printf("\n\t\t*********** 3-返回主菜单 ***********");
|
|
|
printf("\n\t\t************************************************");
|
|
|
printf("\n\t\t请选择:");
|
|
|
choic=getch();
|
|
|
switch (choic)
|
|
|
{
|
|
|
case '1':deleteall();break;
|
|
|
case '2':deleteone();break;
|
|
|
case '3':mainmenu();break;
|
|
|
default:mainmenu();break;
|
|
|
}
|
|
|
}
|
|
|
void deleteall()//删除所有
|
|
|
{
|
|
|
printf("\n\t\t确认删除?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
{
|
|
|
fclose(fp);
|
|
|
if ((fp=fopen("student.bin","wb"))==NULL)
|
|
|
{
|
|
|
printf("\n\t\t不能打开文件,删除失败");
|
|
|
readfromfile();
|
|
|
}
|
|
|
num=0;
|
|
|
printf("\n\t\t记录已删除,按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
return;
|
|
|
}
|
|
|
void deletebyname()//按姓名删除
|
|
|
{
|
|
|
int a=0;
|
|
|
int findmark=0;
|
|
|
int j;
|
|
|
int deletemark=0;
|
|
|
int i;
|
|
|
char name[20];
|
|
|
printf("\n\t\t请输入要删除姓名:");
|
|
|
scanf("%s",name);
|
|
|
for (i=a;i<num;i++)
|
|
|
{
|
|
|
if (strcmp(student[i].name,name)==NULL)
|
|
|
{
|
|
|
printf("\n\t\t以下是您要删除的记录:");
|
|
|
findmark++;
|
|
|
printf("\n\t\t________________________________");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t________________________________");
|
|
|
printf("\n\t\t是否删除?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
{
|
|
|
for (j=i;j<num-1;j++) /*记录移动,从stud数组中删除之*/
|
|
|
student[j]=student[j+1];
|
|
|
num--;
|
|
|
deletemark++;
|
|
|
printf("\n\t\t删除成功");
|
|
|
if((i+1)<num)
|
|
|
{
|
|
|
printf("\n\t\t是否继续删除相同姓名的联系人信息?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
{
|
|
|
a=i;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
printf("\n\t\t是否继续删除?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
deletebyname();
|
|
|
return;
|
|
|
}
|
|
|
if((i+1)<num)
|
|
|
{
|
|
|
printf("\n\t\t是否继续删除相同姓名的联系人信息?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
{
|
|
|
a=i;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
continue;
|
|
|
}
|
|
|
if ((deletemark==0)&&(findmark==0))
|
|
|
{
|
|
|
printf("\n\t\t没有该联系人的纪录");
|
|
|
printf("\n\t\t是否继续删除?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
deletebynativeplace();
|
|
|
return;
|
|
|
}
|
|
|
else if (findmark!=0)
|
|
|
{
|
|
|
printf("\n\t\t没有重名信息");
|
|
|
printf("\n\t\t没有该联系人的纪录");
|
|
|
printf("\n\t\t是否继续删除?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
deletebynativeplace();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
void deleteone()//删除单个
|
|
|
{
|
|
|
char choic;
|
|
|
printf("\n\t\t1-按籍贯删除 2-按姓名删除");
|
|
|
printf("\n\t\t请选择:");
|
|
|
choic=getch();
|
|
|
switch (choic)
|
|
|
{
|
|
|
case '1':deletebynativeplace();break;
|
|
|
case '2':deletebyname();break;
|
|
|
}
|
|
|
}
|
|
|
void deletebynativeplace()//按籍贯删除
|
|
|
{
|
|
|
int i,j;
|
|
|
int deletemark=0;
|
|
|
char nativeplace[20];
|
|
|
printf("\n\t\t请输入要删除联系人籍贯:");
|
|
|
scanf("%s",nativeplace);
|
|
|
if(num==0)
|
|
|
{
|
|
|
printf("\n\t\t对不起,文件中无任何纪录");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
for (i=0;i<num;i++)
|
|
|
{
|
|
|
if (strcmp(student[i].nativeplace,nativeplace)==NULL)
|
|
|
{
|
|
|
printf("\n\t\t以下是您要删除的联系人记录:");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t是否删除?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
{
|
|
|
for (j=i;j<num-1;j++) /*纪录移动,从stud数组中删除之*/
|
|
|
student[j]=student[j+1];
|
|
|
num--;
|
|
|
deletemark++;
|
|
|
printf("\n\t\t删除成功");
|
|
|
printf("\n\t\t是否继续删除?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
deletebynativeplace();
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
return;
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
if (deletemark==0)
|
|
|
{
|
|
|
printf("\n\t\t没有该联系人的记录");
|
|
|
printf("\n\t\t是否继续删除?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
deletebynativeplace();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void modify()//修改联系人
|
|
|
{
|
|
|
char c;
|
|
|
int mark=0;
|
|
|
int i;
|
|
|
int a=0;
|
|
|
if(num==0)
|
|
|
{
|
|
|
printf("\n\t\t对不起,文件中无任何记录");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
system("cls");
|
|
|
printf("\n\t\t********* 修改联系人菜单 *********");
|
|
|
printf("\n\t\t** 1-按姓名修改 2-按电话1修改 **");
|
|
|
printf("\n\t\t** 3-按电话2修改 **");
|
|
|
printf("\n\t\t********任意键-返回主菜单*********");
|
|
|
c=getch();
|
|
|
switch(c)
|
|
|
{
|
|
|
case '1':modifyname();break;
|
|
|
case '2':modifyphone1();break;
|
|
|
case '3':modifyphone2();break;
|
|
|
default:mainmenu();break;
|
|
|
}
|
|
|
}
|
|
|
void modifyname()//按姓名修改
|
|
|
{
|
|
|
char choic;
|
|
|
int i;
|
|
|
int mark=0;
|
|
|
int a=0;
|
|
|
char name[20];
|
|
|
printf("\n\t\t请输入要修改联系人姓名:");
|
|
|
scanf("%s",name);
|
|
|
for(i=0;i<num;i++)
|
|
|
{
|
|
|
if(strcmp(student[i].name,name)==0)
|
|
|
{
|
|
|
printf("\n\t\t******以下是您要修改的联系人信息******");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t是否修改(y/n)");
|
|
|
if(getch()=='y')
|
|
|
{
|
|
|
printf("\n\t\t******** 请选择修改信息 ********");
|
|
|
printf("\n\t\t** 1-修改姓名 2-修改电话1 **");
|
|
|
printf("\n\t\t** 3-修改电话2 4-修改籍贯 **");
|
|
|
printf("\n\t\t** 5-修改电子邮箱 ********");
|
|
|
printf("\n\t\t********************************");
|
|
|
printf("\n\t\t请选择:");
|
|
|
scanf("%s",&choic);
|
|
|
switch(choic)
|
|
|
{
|
|
|
case '1':printf("\n\t\t请输入新名字:");
|
|
|
scanf("%s",student[i].name);break;
|
|
|
case '2':printf("\n\t\t请输入新电话1:");
|
|
|
scanf("%s",student[i].phone1);break;
|
|
|
case '3':printf("\n\t\t请输入新电话2:");
|
|
|
scanf("%s",student[i].phone2);break;
|
|
|
case '4':printf("\n\t\t请输入新籍贯:");
|
|
|
scanf("%s",student[i].nativeplace);break;
|
|
|
case '5':printf("\n\t\t请输入新电子邮箱:");
|
|
|
scanf("%s",student[i].e_mail);break;
|
|
|
}printf("\n\t\t是否继续修改?(y/n);");
|
|
|
if(getch()=='y')
|
|
|
modifyname();
|
|
|
return;
|
|
|
}
|
|
|
mark++;
|
|
|
}
|
|
|
}
|
|
|
if(mark==0)
|
|
|
{
|
|
|
printf("\n\t\t没有找到联系人信息");
|
|
|
printf("\n\t\t是否继续修改?(Y/N);");
|
|
|
if(getch()=='Y')
|
|
|
modifyname();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
void modifyphone1()//按电话1修改
|
|
|
{
|
|
|
char choic;
|
|
|
char phone1[20];
|
|
|
int i;
|
|
|
int mark=0;
|
|
|
int a=0;
|
|
|
printf("\n\t\t请输入要修改联系人的号码1:");
|
|
|
scanf("%s",phone1);
|
|
|
for(i=0;i<num;i++)
|
|
|
{
|
|
|
if(strcmp(student[i].phone1,phone1)==0)
|
|
|
{
|
|
|
printf("\n\t\t******以下是您要修改的联系人信息******");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t是否修改(y/n)");
|
|
|
mark++;
|
|
|
if(getch()=='y')
|
|
|
{
|
|
|
printf("\n\t\t******** 请选择修改信息 ********");
|
|
|
printf("\n\t\t** 1-修改姓名 2-修改电话1 **");
|
|
|
printf("\n\t\t** 3-修改电话2 4-修改籍贯 **");
|
|
|
printf("\n\t\t** 5-修改电子邮箱 ********");
|
|
|
printf("\n\t\t********************************");
|
|
|
printf("\n\t\t请选择:");
|
|
|
scanf("%s",&choic);
|
|
|
switch(choic)
|
|
|
{
|
|
|
case '1':printf("\n\t\t请输入新名字:");
|
|
|
scanf("%s",student[i].name);break;
|
|
|
case '2':printf("\n\t\t请输入新电话1:");
|
|
|
scanf("%s",student[i].phone1);break;
|
|
|
case '3':printf("\n\t\t请输入新电话2:");
|
|
|
scanf("%s",student[i].phone2);break;
|
|
|
case '4':printf("\n\t\t请输入新籍贯:");
|
|
|
scanf("%s",student[i].nativeplace);break;
|
|
|
case '5':printf("\n\t\t请输入新电子邮箱:");
|
|
|
scanf("%s",student[i].e_mail);break;
|
|
|
}printf("\n\t\t是否继续修改?(y/n);");
|
|
|
if(getch()=='y')
|
|
|
modifyname();
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
mark++;
|
|
|
}
|
|
|
}
|
|
|
if(mark==0)
|
|
|
{
|
|
|
printf("\n\t\t没有找到联系人信息");
|
|
|
printf("\n\t\t是否继续修改?(Y/N);");
|
|
|
if(getch()=='Y')
|
|
|
modifyname();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
void modifyphone2()//按电话2修改
|
|
|
{
|
|
|
char choic;
|
|
|
char phone2[20];
|
|
|
int i;
|
|
|
int mark=0;
|
|
|
int a=0;
|
|
|
printf("\n\t\t请输入要修改联系人的号码2:");
|
|
|
scanf("%s",phone2);
|
|
|
for(i=0;i<num;i++)
|
|
|
{
|
|
|
if(strcmp(student[i].phone2,phone2)==0)
|
|
|
{
|
|
|
printf("\n\t\t******以下是您要修改的联系人信息******");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t是否修改(y/n)");
|
|
|
mark++;
|
|
|
if(getch()=='y')
|
|
|
{
|
|
|
printf("\n\t\t******** 请选择修改信息 ********");
|
|
|
printf("\n\t\t** 1-修改姓名 2-修改电话1 **");
|
|
|
printf("\n\t\t** 3-修改电话2 4-修改籍贯 **");
|
|
|
printf("\n\t\t** 5-修改电子邮箱 ********");
|
|
|
printf("\n\t\t********************************");
|
|
|
printf("\n\t\t请选择:");
|
|
|
scanf("%s",&choic);
|
|
|
switch(choic)
|
|
|
{
|
|
|
case '1':printf("\n\t\t请输入新名字:");
|
|
|
scanf("%s",student[i].name);break;
|
|
|
case '2':printf("\n\t\t请输入新电话1:");
|
|
|
scanf("%s",student[i].phone1);break;
|
|
|
case '3':printf("\n\t\t请输入新电话2:");
|
|
|
scanf("%s",student[i].phone2);break;
|
|
|
case '4':printf("\n\t\t请输入新籍贯:");
|
|
|
scanf("%s",student[i].nativeplace);break;
|
|
|
case '5':printf("\n\t\t请输入新电子邮箱:");
|
|
|
scanf("%s",student[i].e_mail);break;
|
|
|
}printf("\n\t\t是否继续修改?(y/n);");
|
|
|
if(getch()=='y')
|
|
|
modifyname();
|
|
|
return;
|
|
|
}
|
|
|
mark++;
|
|
|
}
|
|
|
}
|
|
|
if(mark==0)
|
|
|
{
|
|
|
printf("\n\t\t没有找到联系人信息");
|
|
|
printf("\n\t\t是否继续修改?(Y/N);");
|
|
|
if(getch()=='Y')
|
|
|
modifyname();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
void showall()//显示所有
|
|
|
{
|
|
|
int i;
|
|
|
system("cls");
|
|
|
if(num!=0)
|
|
|
{
|
|
|
printf("\n\t\t*************** 以下为通讯录所有信息************");
|
|
|
for (i=0;i<num;i++)
|
|
|
{
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\t\t");
|
|
|
if (i+1<num)
|
|
|
{
|
|
|
printf("\n\t\t__________________________");
|
|
|
system("pause");
|
|
|
}
|
|
|
}
|
|
|
printf("\n\t\t************************************************");
|
|
|
}
|
|
|
else
|
|
|
printf("\n\t\t通讯录中无任何纪录");
|
|
|
printf("\n\t\t按任意键返回主菜单:");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
void searchmenu()//查询菜单
|
|
|
{
|
|
|
char choic;
|
|
|
system("cls");
|
|
|
printf("\n\t\t******************* 查询菜单 **********************");
|
|
|
printf("\n\t\t********** 1-显示所有 2-按籍贯查询 *************");
|
|
|
printf("\n\t\t********** 3-按姓名查询 4-按电话1查询 ************");
|
|
|
printf("\n\t\t********** 5-按电话2查询 6-返回主菜单 *************");
|
|
|
printf("\n\t\t***************************************************");
|
|
|
printf("\n\t\t请选择:");
|
|
|
choic=getch();
|
|
|
switch (choic)
|
|
|
{
|
|
|
case '1':showall();break;
|
|
|
case '2':searchbynativeplace();break;
|
|
|
case '3':searchbyname();break;
|
|
|
case '4':searchbyphone1();break;
|
|
|
case '5':searchbyphone2();break;
|
|
|
case '6':mainmenu();break;
|
|
|
}
|
|
|
}
|
|
|
void searchbynativeplace()//按籍贯查询
|
|
|
{
|
|
|
int mark=0;
|
|
|
int i;
|
|
|
int a=0;
|
|
|
printf("\n\t\t****************** 按籍贯查找 ******************\n");
|
|
|
char nativeplace[20];
|
|
|
printf("\n\t\t请输入籍贯:");
|
|
|
scanf("%s",nativeplace);
|
|
|
for(i=0;i<num;i++)
|
|
|
{
|
|
|
if (strcmp(student[i].nativeplace,nativeplace)==0)
|
|
|
{
|
|
|
printf("\n\t\t************** 以下是您查找的联系人信息 **********");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t************************************************");
|
|
|
printf("\n\t\t按任意键返回主菜单:");
|
|
|
mark++;
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
if (mark==0)
|
|
|
{
|
|
|
printf("\n\t\t没有修改联系人的信息");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
void searchbyname()//按姓名查询
|
|
|
{
|
|
|
int mark=0;
|
|
|
int i;
|
|
|
int a=0;
|
|
|
printf("\n\t\t***************** 按姓名查找 *******************");
|
|
|
char name[20];
|
|
|
printf("\n\t\t请输入姓名:");
|
|
|
scanf("%s",name);
|
|
|
for(i=a;i<num;i++)
|
|
|
{
|
|
|
if (strcmp(student[i].name,name)==0)
|
|
|
{
|
|
|
printf("\n\t\t************* 以下是您查找的联系人信息 ***********");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t************************************************");
|
|
|
mark++;
|
|
|
if ((i+1)<num)
|
|
|
{
|
|
|
printf("\n\t\t是否继续查找相同名字的联系人信息:(y/n)");
|
|
|
if (getch()=='y')
|
|
|
{
|
|
|
a=i;
|
|
|
continue;
|
|
|
}
|
|
|
else
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(mark!=0)
|
|
|
{
|
|
|
printf("\n\t\t没有相同姓名的联系人纪录");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("\n\t\t没有相同姓名的联系人纪录");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
void searchbyphone1()//按电话1查询
|
|
|
{
|
|
|
int mark=0;
|
|
|
int i;
|
|
|
int a=0;
|
|
|
printf("\n\t\t****************** 按电话1查找 ******************");
|
|
|
char phone1[10];
|
|
|
printf("\n\t\t请输入电话1:");
|
|
|
scanf("%s",phone1);
|
|
|
for(i=0;i<num;i++)
|
|
|
{
|
|
|
if (strcmp(student[i].phone1,phone1)==0)
|
|
|
{
|
|
|
printf("\n\t\t************** 以下是您查找的联系人信息 **********");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t************************************************");
|
|
|
printf("\n\t\t按任意键返回主菜单:");
|
|
|
mark++;
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
if (mark==0)
|
|
|
{
|
|
|
printf("\n\t\t没有修改联系人的信息");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
void searchbyphone2() //按电话2查询
|
|
|
{
|
|
|
int mark=0;
|
|
|
int i;
|
|
|
int a=0;
|
|
|
printf("\n\t\t****************** 按电话2查找 ******************");
|
|
|
char phone2[10];
|
|
|
printf("\n\t\t请输入电话2:");
|
|
|
scanf("%s",phone2);
|
|
|
for(i=0;i<num;i++)
|
|
|
{
|
|
|
if (strcmp(student[i].phone2,phone2)==0)
|
|
|
{
|
|
|
printf("\n\t\t************** 以下是您查找的联系人信息 **********");
|
|
|
printf("\n\t\t籍贯: %s",student[i].nativeplace);
|
|
|
printf("\n\t\t姓名: %s",student[i].name);
|
|
|
printf("\n\t\t电话1: %s",student[i].phone1);
|
|
|
printf("\n\t\t电话2: %s",student[i].phone2);
|
|
|
printf("\n\t\te-mail:%s",student[i].e_mail);
|
|
|
printf("\n\t\t************************************************");
|
|
|
printf("\n\t\t按任意键返回主菜单:");
|
|
|
mark++;
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
if (mark==0)
|
|
|
{
|
|
|
printf("\n\t\t没有修改联系人的信息");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
void listmenu()//排序菜单
|
|
|
{
|
|
|
char choic;
|
|
|
if(num==0)
|
|
|
{
|
|
|
printf("\n\t\t对不起,文件中无任何纪录");
|
|
|
printf("\n\t\t按任意键返回主菜单");
|
|
|
getch();
|
|
|
return;
|
|
|
}
|
|
|
system("cls");
|
|
|
printf("\n\t\t******************* 排序菜单 *******************");
|
|
|
printf("\n\t\t********** 1-按籍贯排序 2-按姓名排序 **********");
|
|
|
printf("\n\t\t********** 3-返回主菜单 **********");
|
|
|
printf("\n\t\t************************************************");
|
|
|
printf("\n\t\t请选择:");
|
|
|
choic=getch();
|
|
|
switch(choic)
|
|
|
{
|
|
|
case '1':listbynativeplace();break;
|
|
|
case '2':listbyname();break;
|
|
|
case '3':mainmenu();break;
|
|
|
default:mainmenu();break;
|
|
|
}
|
|
|
}
|
|
|
void listbynativeplace()//按籍贯排序
|
|
|
{
|
|
|
int i,j;
|
|
|
struct record tmp;
|
|
|
for (i=1;i<num;i++)
|
|
|
{
|
|
|
if(strcmp(student[i].nativeplace,student[i-1].nativeplace)<0)
|
|
|
{
|
|
|
tmp=student[i];
|
|
|
j=i-1;
|
|
|
do
|
|
|
{
|
|
|
student[j+1]=student[j];
|
|
|
j--;
|
|
|
}while ((strcmp(tmp.nativeplace,student[j].nativeplace)<0)&&j>=0);
|
|
|
student[j+1]=tmp;
|
|
|
}
|
|
|
}
|
|
|
printf("\n\t\t排序成功,是否显示?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
showall();
|
|
|
return;
|
|
|
}
|
|
|
void listbyname()//按姓名排序
|
|
|
{
|
|
|
int i,j;
|
|
|
struct record tmp;
|
|
|
for (i=1;i<num;i++)
|
|
|
{
|
|
|
if(strcmp(student[i].name,student[i-1].name)<0)
|
|
|
{
|
|
|
tmp=student[i];
|
|
|
j=i-1;
|
|
|
do
|
|
|
{
|
|
|
student[j+1]=student[j];
|
|
|
j--;
|
|
|
}while ((strcmp(tmp.name,student[j].name)<0&&j>=0));
|
|
|
student[j+1]=tmp;
|
|
|
}
|
|
|
}
|
|
|
printf("\n\t\t排序成功,是否显示?(y/n)");
|
|
|
if (getch()=='y')
|
|
|
showall();
|
|
|
return;
|
|
|
}
|