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.

213 lines
4.3 KiB

6 years ago
#include <stdio.h>
#include <process.h>
#include <stdlib.h>
#include <string.h>
//<2F><><EFBFBD><EFBFBD><E5BAAF>
FILE *fp; //<2F>ļ<EFBFBD>ָ<EFBFBD><D6B8>
void menu();
void add();
void search();
void modify();
void look();
void quit();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int main()
{
menu();
return 0;
}
//ͨѶ¼<D1B6><EFBFBD><E1B9B9>
struct user
{
char name[8]; //<2F><><EFBFBD><EFBFBD>
char place[15]; //<2F><><EFBFBD><EFBFBD>
char tel1[15]; //<2F>绰1
char tel2[15]; //<2F>绰2
char email[20]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}user[50];
//<2F>˵<EFBFBD>
void menu()
{
system("cls");
system("color f3");
int n;
printf("\n\n\n\n\n");
printf("\t\t:---------ͨѶ¼---------:\n");
printf("\t\t: 1:<3A>½<EFBFBD> :\n");
printf("\t\t: 2:<3A><>ѯ :\n");
printf("\t\t: 3:<3A>޸<EFBFBD> :\n");
printf("\t\t: 4:<3A><><EFBFBD><EFBFBD> :\n");
printf("\t\t: 5:<3A>˳<EFBFBD> :\n");
printf("\t\t:--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <1-5>ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>--:\n\n");
scanf("%d",&n);
switch(n)
{
case 1: add(); break; //<2F><><EFBFBD><EFBFBD>
case 2: search(); break; //<2F><>ѯ
case 3: modify(); break; //<2F>޸<EFBFBD>
case 4: look(); break; //<2F><><EFBFBD><EFBFBD>
case 5: return; break; //<2F>˳<EFBFBD>
default: return;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ
void add()
{
struct user one;
system("color e3");
if((fp=fopen("user.txt","ab"))==NULL)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
exit(0);
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%s",one.name);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%s",one.place);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>");
scanf("%s",one.tel1);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><EFBFBD>");
scanf("%s",one.tel2);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%s",one.email);
fwrite(&one,sizeof(struct user),1,fp); //<2F><><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>¼<EFBFBD><C2BC>user.txt<78><74>
fclose(fp);
printf("\nע<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
system("pause");
menu();
};
//<2F>޸<EFBFBD>
void modify()
{
6 years ago
char namekey[8];
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%s",namekey);
if((fp=fopen("user.txt","ab+"))==NULL) //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>\n");
exit(0);
}
int m=0,t=1;
while(!feof(fp))
{
fread(&user[m],sizeof(struct user),1,fp)==1; //<2F><>ȡ<EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ
if(!strcmp(user[m].name,namekey)) //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ
{
t=0; //<2F><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD>if<69><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
}
m++;
}
if(t)
printf("δ<EFBFBD>ҵ<EFBFBD>\n"),fclose(fp),system("pause"),menu();
else
{
printf("<EFBFBD>ҵ<EFBFBD>\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\t<EFBFBD>绰1\t\t<EFBFBD>绰2\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("%-8s\t",user[m].name);
printf("%-15s\t",user[m].place);
printf("%-15s\t",user[m].tel1);
printf("%-15s\t",user[m].tel2);
printf("%-20s\t",user[m].email);
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n\n1.<2E><><EFBFBD><EFBFBD>\t2.<2E><><EFBFBD><EFBFBD>\t3.<2E>绰1\t4.<2E>绰2\t5.<2E><><EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<2E><><EFBFBD>޸<EFBFBD>"); //<2F>޸<EFBFBD><DEB8><EFBFBD>Ϣ<EFBFBD><CFA2>ʾ
int a; //<2F>޸ĵ<DEB8><C4B5><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
scanf("%d",&a);
char *newname;
char nweplace[15];
char newtel1[15];
char newtel2[15];
char newemail[20];
switch(a)
{
case 1:scanf("%s",newname),strcpy(user[m].name,newname),printf("%s",user[m].name);break;
default:break;
}
printf("<EFBFBD>޸ijɹ<EFBFBD>\n");
fclose(fp);
system("pause");
6 years ago
menu();
}
//<2F><>ѯ
void search()
{
6 years ago
char namekey[8];
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%s",namekey);
if((fp=fopen("user.txt","r"))==NULL) //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>\n");
exit(0);
}
int m=0,t=0;
while(!feof(fp))
{
fread(&user[m],sizeof(struct user),1,fp)==1; //<2F><>ȡ<EFBFBD><EFBFBD><E1B9B9><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ
if(!strcmp(user[m].name,namekey)) //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ
{
t=1; //<2F><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD>if<69><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
}
m++;
}
if(t)
{
printf("<EFBFBD>ҵ<EFBFBD>\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\t<EFBFBD>绰1\t\t<EFBFBD>绰2\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("%-8s\t",user[m].name);
printf("%-15s\t",user[m].place);
printf("%-15s\t",user[m].tel1);
printf("%-15s\t",user[m].tel2);
printf("%-20s\t",user[m].email);
}
else
printf("δ<EFBFBD>ҵ<EFBFBD>\n");
fclose(fp);
system("pause");
6 years ago
menu();
}
//<2F><><EFBFBD><EFBFBD>
void look()
{
6 years ago
char c;
if((fp=fopen("user.txt","r"))==NULL) //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>user.txt
{
printf("<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>Ϣʧ<EFBFBD>ܣ<EFBFBD>\n");
exit(0);
}
int m=0;
while(!feof(fp))
{
if(fread(&user[m],sizeof(struct user),1,fp)==1)
m++;
}
int i;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\t<EFBFBD>绰1\t\t<EFBFBD>绰2\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
for(i=0;i<m;i++)
{
printf("%-8s\t",user[i].name);
printf("%-15s\t",user[i].place);
printf("%-15s\t",user[i].tel1);
printf("%-15s\t",user[i].tel2);
printf("%-20s\t",user[i].email);
printf("\n");
}
if(fclose(fp)) //<2F>ر<EFBFBD><D8B1>ļ<EFBFBD>
{
printf("<EFBFBD>ر<EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>\n");
exit(0);
}
scanf("%c",&c);
printf("<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Y/N<><4E><EFBFBD><EFBFBD>");
scanf("%c",&c);
if(c=='y'||c=='Y')
6 years ago
menu();
return;
}
//<2F>˳<EFBFBD>
void quit()
{
return;
}