|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
struct person
|
|
|
|
|
{
|
|
|
|
|
char name[20];
|
|
|
|
|
char tel1[12];
|
|
|
|
|
char tel2[12];
|
|
|
|
|
char email[20];
|
|
|
|
|
char addr[20];
|
|
|
|
|
};
|
|
|
|
|
char filename[20];
|
|
|
|
|
FILE *fp;
|
|
|
|
|
void menu();
|
|
|
|
|
void creat();
|
|
|
|
|
void delete();
|
|
|
|
|
void xiugai();
|
|
|
|
|
void output();
|
|
|
|
|
void search();
|
|
|
|
|
void search1();
|
|
|
|
|
void search2();
|
|
|
|
|
void append();
|
|
|
|
|
main()
|
|
|
|
|
{
|
|
|
|
|
creat();
|
|
|
|
|
menu();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
void menu()
|
|
|
|
|
{
|
|
|
|
|
int m;
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\t\t*************<2A><>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨѶ¼<D1B6><C2BC>************\n\n");
|
|
|
|
|
printf("\n\t\t***********<2A><><EFBFBD>ӣ<EFBFBD> <20>밴1***********");
|
|
|
|
|
printf("\n\t\t***********<2A><><EFBFBD>ң<EFBFBD> <20>밴2***********");
|
|
|
|
|
printf("\n\t\t***********<2A>ģ<DEB8> <20>밴3***********");
|
|
|
|
|
printf("\n\t\t***********ɾ<><C9BE><EFBFBD><EFBFBD> <20>밴4***********");
|
|
|
|
|
printf("\n\t\t***********<2A><>ʾȫ<CABE><C8AB><EFBFBD><EFBFBD>ϵ<EFBFBD>ˣ<EFBFBD><CBA3>밴5***********");
|
|
|
|
|
printf("\n\t\t***********<2A>˳<EFBFBD><CBB3><EFBFBD> <20>밴0***********\n");
|
|
|
|
|
printf("\n\t\t*******************************************\n\n");
|
|
|
|
|
printf("Please select(0--5):");
|
|
|
|
|
scanf("%d",&m);
|
|
|
|
|
if(m>=0&&m<=4)
|
|
|
|
|
{
|
|
|
|
|
switch(m)
|
|
|
|
|
{
|
|
|
|
|
case 1: append();
|
|
|
|
|
break;
|
|
|
|
|
case 2: search();
|
|
|
|
|
break;
|
|
|
|
|
case 3: xiugai();
|
|
|
|
|
break;
|
|
|
|
|
case 4: delete();
|
|
|
|
|
break;
|
|
|
|
|
case 5: output();
|
|
|
|
|
break;
|
|
|
|
|
case 0: exit(0);
|
|
|
|
|
}
|
|
|
|
|
printf("\n\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴ<EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("\n\nѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴ<EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void creat()
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD>绰<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
scanf("%s",filename);
|
|
|
|
|
if((fp=fopen(filename,"at+"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><EFBFBD>绰<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD>");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
fprintf(fp,"%-20s%-12s%-12s%-20s%-20s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD>绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1","<EFBFBD>绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>2","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void output()
|
|
|
|
|
{
|
|
|
|
|
struct person one;
|
|
|
|
|
if((fp=fopen(filename,"r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>ͨѶ¼<EFBFBD><EFBFBD>");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
printf("\n\n%20s\n","ͨ Ѷ ¼");
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%s%s%s%s%s\n",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
printf("%-20s%-12s%-12s%-20s%-20s",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void append()
|
|
|
|
|
{
|
|
|
|
|
struct person one;
|
|
|
|
|
search2();
|
|
|
|
|
if((fp=fopen(filename,"a"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>ͨѶ¼<EFBFBD><EFBFBD>");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD>绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>估<EFBFBD><EFBFBD><EFBFBD>ᣨ<EFBFBD>ÿո<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
scanf("%s%s%s%s%s",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
fprintf(fp,"%-20s%-12s%-12s%-20s%-20s\n",one.name,one.tel,one.addr);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void search()
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
printf("\n\t\t*******************************");
|
|
|
|
|
printf("\n\t\t*****<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ң<EFBFBD> <20>밴1*****");
|
|
|
|
|
printf("\n\t\t*****<2A><><EFBFBD>绰<EFBFBD><E7BBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ң<EFBFBD><D2A3>밴2*****");
|
|
|
|
|
printf("\n\t\t*****<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD> <20>밴0*****");
|
|
|
|
|
printf("\n\t\t*******************************\n");
|
|
|
|
|
printf("Please select(0--2):");
|
|
|
|
|
scanf("%d",n);
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1: search1();break;
|
|
|
|
|
case 2: search2();break;
|
|
|
|
|
case 0: menu();break;
|
|
|
|
|
default: printf("\n\nѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴ<EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void search1()
|
|
|
|
|
{
|
|
|
|
|
int k=0;
|
|
|
|
|
char namekey[20];
|
|
|
|
|
struct person one;
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%s",namekey);
|
|
|
|
|
if((fp=fopen(filename,"rb"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD>ܴ绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%s%s%s%s%s\n",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
if(!strcmp(namekey,one.name))
|
|
|
|
|
{
|
|
|
|
|
printf("\n\n<EFBFBD>Ѳ鵽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼Ϊ<EFBFBD><EFBFBD>");
|
|
|
|
|
printf("\n%-20s%-12s%-12s%-20s%-20s",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
k=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!k)
|
|
|
|
|
printf("\n\n<EFBFBD>Բ<EFBFBD><EFBFBD>𣬵绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>д<EFBFBD><EFBFBD>˵ļ<EFBFBD>¼<EFBFBD><EFBFBD>");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void search2()
|
|
|
|
|
{
|
|
|
|
|
int k=0;
|
|
|
|
|
char telkey[12];
|
|
|
|
|
struct person one;
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%s",telkey);
|
|
|
|
|
if((fp=fopen(filename,"rb"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD>ܴ绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%s%s%s%s%s\n",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
if(!strcmp(telkey,one.tel1)||!strcmp(telkey,one.tel2))
|
|
|
|
|
{
|
|
|
|
|
printf("\n\n<EFBFBD>Ѳ鵽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼Ϊ<EFBFBD><EFBFBD>");
|
|
|
|
|
printf("\n%-20s%-12s%-12s%-20s%-20s",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
k=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!k)
|
|
|
|
|
printf("\n\n<EFBFBD>Բ<EFBFBD><EFBFBD>𣬵绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>д<EFBFBD><EFBFBD>˵ļ<EFBFBD>¼<EFBFBD><EFBFBD>");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void xiugai()
|
|
|
|
|
{
|
|
|
|
|
char name[20];
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
scanf("%s",name);
|
|
|
|
|
if((fp=fopen(filename,"rb"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD>ܴ绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
fscanf(fp,"%s%s%s%s%s\n",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
if(!strcmp(name,one.name))
|
|
|
|
|
{
|
|
|
|
|
printf("\n\n<EFBFBD>Ѳ鵽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼Ϊ<EFBFBD><EFBFBD>");
|
|
|
|
|
printf("\n%-20s%-12s%-12s%-20s%-20s",one.name,one.tel1,one.tel2,one.email,one.addr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void delete()
|
|
|
|
|
{
|
|
|
|
|
}
|