#include
#include
#include
void firstwindow();
void xinxichaxun();
void xinxixianshi();
void shaixuan(int a);
void zengjiarenyuan();
void xinxichaxun1(int a);
void xiugaixinxi();
void xianshi();
struct people
{
char name[20];
char haoma[20];
char fenlei[20];
};
void shuru(struct people men[],int j);
void shanchu1(struct people men[],int j);
void shanchu();
int main()
{
printf("\t|----------------------------------------------------------------------|\n");
printf("\t|-------------------欢迎进入手机通讯录管理系统-------------------------|\n");
printf("\n");
printf("\t| ***** ****** ***** ****** ***** ****** |\n");
printf("\t| ** ** ** ** ** ** ** ** ** |\n");
printf("\t| ** ** ** ** ** ** ** ** ** |\n");
printf("\t| ** YANG ** ** ZI ** ** WEI ** |\n");
printf("\t| ** ** ** ** ** ** |\n");
printf("\t| ** ** ** |\n");
_sleep(300);
system("cls");
firstwindow();
}
void firstwindow()
{
printf("\t|------------------------------------------------------------|\n");
printf("\t|---------------------------MENU-----------------------------|\n");
printf("\n");
printf("\t|-----------------请输入你想要进行的操作编号-----------------|\n");
printf("\n");
printf("\t 1.信息显示\n");
printf("\n");
printf("\t 2.信息查询\n");
printf("\n");
printf("\t 3.增加人员\n");
printf("\n");
printf("\t 4.修改信息\n");
printf("\n");
printf("\t 5.删除信息\n");
printf("\n");
printf("\t 6.显示所有信息\n");
printf("\n");
printf("\t 7.关闭\n");
int a;
scanf("%d",&a);
switch(a)
{
case 1:xinxixianshi();break;
case 2:xinxichaxun();break;
case 3:zengjiarenyuan();break;
case 4:xiugaixinxi();break;
case 5:shanchu();break;
case 6:xianshi();break;
case 7:break;
}
}
void xinxixianshi()
{
system("cls");
printf("\t|------------------------------------------------------------|\n");
printf("\n");
printf("\t|-----------------请选择以下三种类别的信息-------------------|\n");
printf("\n");
printf("\t 1.师兄\n");
printf("\n");
printf("\t 2.朋友\n");
printf("\n");
printf("\t 3.亲属\n");
int b;
scanf("%d",&b);
switch (b)
{
case 1:shaixuan(1);break;
case 2:shaixuan(2);break;
case 3:shaixuan(3);break;
}
}
void shaixuan(int a)
{
struct people men[20];
FILE *fp;
fp=fopen("f1.txt","a+");
int i=0,j=0;
while(!feof(fp))
{
fscanf(fp,"%s %s %s",men[i].name,men[i].haoma,men[i].fenlei);
i++;
j++;
}
if(a==1)
{
for(i=0;i
{
if(strcmp(men[i].fenlei,"师兄")==0)
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
}
if(a==2)
{
for(i=0;i
{
if(strcmp(men[i].fenlei,"朋友")==0)
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
}
if(a==3)
{
for(i=0;i
{
if(strcmp(men[i].fenlei,"亲属")==0)
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
}
printf("输入1继续,0结束程序\n");
int c;
scanf("%d",&c);
if(c==1)
{
system("cls");
firstwindow();
}
else if(c==0)
return 0;
}
void xinxichaxun()
{
system("cls");
printf("\t|------------------------------------------------------------|\n");
printf("\n");
printf("\t 1.按姓名查询 \n");
printf("\n");
printf("\t 2.按号码查询 \n");
printf("\n");
printf("\t|------------------------------------------------------------|\n");
int a;
scanf("%d",&a);
switch(a)
{
case 1:xinxichaxun1(1);break;
case 2:xinxichaxun1(2);break;
}
}
void xinxichaxun1(int a)
{
struct people men[20];
char chaxun[20];
FILE *fp;
fp=fopen("f1.txt","a+");
int i=0,j=0;
while(!feof(fp))
{
fscanf(fp,"%s %s %s",men[i].name,men[i].haoma,men[i].fenlei);
i++;
j++;
}
if(a==1)
{
printf("请输入姓名\n");
scanf("%s",chaxun);
for(i=0;i
{
if(strcmp(men[i].name,chaxun)==0)
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
}
if(a==2)
{
printf("请输入号码\n");
scanf("%s",chaxun);
for(i=0;i
{
if(strcmp(men[i].haoma,chaxun)==0)
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
}
printf("输入1继续,0结束程序\n");
int c;
scanf("%d",&c);
if(c==1)
{
system("cls");
firstwindow();
}
else if(c==0)
return 0;
}
void zengjiarenyuan()
{
char name[20],haoma[20],fenlei[20];
printf("请输入你想要增加的信息,名字,号码,关系,用空格隔开\n");
scanf("%s %s %s",name,haoma,fenlei);
struct people men[50];
FILE *fp;
fp=fopen("f1.txt","a+");
int i=0,j=0,k=0;
while(!feof(fp))
{
fscanf(fp,"%s%s%s",men[i].name,men[i].haoma,men[i].fenlei);
i++;
j++;
}
for(i=0;i
{
if(strcmp(men[i].name,name)==0)
{
printf("名字已有请重新输入\n");
k=1;
break;
}
if(strcmp(men[i].haoma,haoma)==0)
{
printf("号码已有请重新输入\n");
k=1;
break;
}
}
if(k==0)
fprintf(fp,"%s %s %s\n",name,haoma,fenlei);
fclose(fp);
if(k==0)
printf("OK!");
_sleep(1000);
system("cls");
firstwindow();
}
void xiugaixinxi()
{
struct people men[20];
FILE *fp;
fp=fopen("f1.txt","r");
int i=0,j=0;
while(!feof(fp))
{
fscanf(fp,"%s %s %s",men[i].name,men[i].haoma,men[i].fenlei);
i++;
j++;
}
for(i=0;i
{
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
char name[20],haoma[20],fenlei[20];
printf("请输入你想修改信息人的名字\n");
scanf("%s",name);
printf("输入1修改号码,输入2修改类别\n");
int d;
scanf("%d",&d);
if(d==1)
{
printf("输入号码\n");
scanf("%s",haoma);
for(i=0;i
{
if(strcmp(men[i].name,name)==0)
{
strcpy(men[i].haoma,haoma);
}
}
}
if(d==2)
{
printf("输入类别\n");
scanf("%s",fenlei);
for(i=0;i
{
if(strcmp(men[i].name,name)==0)
{
strcpy(men[i].fenlei,fenlei);
}
}
}
for(i=0;i
{
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
fclose(fp);
shuru(men,j);
printf("OK!");
_sleep(1000);
system("cls");
firstwindow();
}
void shuru(struct people men[],int j)
{
FILE *fp;
fp=fopen("f1.txt","w");
int i;
for(i=0;i
{
fprintf(fp,"%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
fclose(fp);
}
void shanchu()
{
struct people men[20];
FILE *fp;
fp=fopen("f1.txt","r");
int i=0,j=0,k;
while(!feof(fp))
{
fscanf(fp,"%s %s %s",men[i].name,men[i].haoma,men[i].fenlei);
i++;
j++;
}
for(i=0;i
{
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
printf("请输入你想删除人的名字\n");
char name[20];
scanf("%s",name);
for(i=0;i
{
if(strcmp(men[i].name,name)==0)
{
for(k=i+1;k
{
men[k-1]=men[k];
}
break;
}
}
fclose(fp);
shanchu1(men,j);
printf("OK!");
_sleep(1000);
system("cls");
firstwindow();
}
void shanchu1(struct people men[],int j)
{
FILE *fp;
fp=fopen("f1.txt","w");
int i;
for(i=0;i
{
fprintf(fp,"%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
fclose(fp);
}
void xianshi()
{
struct people men[20],man;
FILE *fp;
fp=fopen("f1.txt","r");
int i=0,j=0,k;
while(!feof(fp))
{
fscanf(fp,"%s %s %s",men[i].name,men[i].haoma,men[i].fenlei);
i++;
j++;
}
for(i=0;i
{
for(k=i+1;k
{
if(strcmp(men[i].name,men[k].name)>0)
{
man=men[i];
men[i]=men[k];
men[k]=man;
}
}
}
for(i=0;i
{
printf("%s %s %s\n",men[i].name,men[i].haoma,men[i].fenlei);
}
printf("输入1继续,0结束程序\n");
int c;
scanf("%d",&c);
if(c==1)
{
system("cls");
firstwindow();
}
else if(c==0)
return 0;
}