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.

423 lines
9.2 KiB

6 years ago
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<process.h>
void add();
void finds();
void clean();
void menus();
void delet();
void modify();
FILE *fp;
int num=0;
struct word
{
char en[100];
char ch[100];
char ex[100];
}s[200];
//<2F><><EFBFBD><EFBFBD>
void clean()
{
int choice;
system("cls");
printf("\n") ;
menus();
scanf("%d",&choice);
printf("\n") ;
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();break;
case 5:
modify();break;
case 0:
break;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
void add()
{
int a,b,c,choice;
char next='1';
char word[100];
FILE *fp;
if((fp=fopen("f4.txt","a+"))==NULL)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͷ<EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't open file");
exit(0);
}
fseek(fp,0,SEEK_END);//<2F><>λ<EFBFBD><CEBB><EFBFBD>ļ<EFBFBD>ĩβ
while(next=='1')
{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>Ӣ<EFBFBD><EFBFBD>:");
scanf("%s",s[num].en);
a=fprintf(fp,"%s\t",s[num].en);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%s",s[num].ch);
b=fprintf(fp,"%s\t",s[num].ch);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%s",s[num].ex);
c=fprintf(fp,"%s\t",s[num].ex);
if(a&&b&&c)
{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>\n");
num++;
printf("%d",num);
}
else
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
printf("\nWould you like to enter more items(Yes--1/No--<2D><>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)\n");
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>'#'<27>ż<EFBFBD>") ;
fflush(stdin);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBBBA><EFBFBD><EFBFBD>
next=getch();
}
if(next=='#')
{
printf("\n") ;
menus();
scanf("%d",&choice);
printf("\n") ;
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();break;
case 5:
modify();break;
case 0:
break;
}
}
if(fclose(fp))//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC>ر<EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't close file");
exit(0);
}
}
//<2F><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>
void finds()
{
rewind(fp);
int i,choice,flag=0;
char find='2';
char n;
char w[100];
if((fp=fopen("f4.txt","r"))==NULL)//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͷ<EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't open file");
exit(0);
}
while(find=='2')
{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ҵĵ<EFBFBD><EFBFBD><EFBFBD>:");
scanf("%s",w);
for(i=0;i<=10;i++)//<2F><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
fscanf(fp,"%s\t%s\t%s\t",s[i].en,s[i].ch,s[i].ex);
if(strcmp(s[i].en,w)==0)
{
printf("\nӢ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ <20><><EFBFBD><EFBFBD> ");
printf("\n %-12s%8s%12s",s[i].en,s[i].ch,s[i].ex);
find=1;//<2F>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>
}
else
{
char *res = strstr(s[i].en,w);
if(res != NULL)
{
printf("\n<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>");
printf("%s\n", res);
find=2;
}
}
}
printf("\nWould you like to enter more items(Yes--2/No--<2D><>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)\n");
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>'#'<27>ż<EFBFBD>") ;
fflush(stdin);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBBBA><EFBFBD><EFBFBD>
find=getch();
}
if(find=='#')
{
printf("\n") ;
menus();
scanf("%d",&choice);
printf("\n") ;
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();break;
case 5:
modify();break;
case 0:
break;
}
}
if(fclose(fp))//<2F>ر<EFBFBD><D8B1><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC>ر<EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't close file");
exit(0);
}
}
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
void delet()
{
int choice ;
FILE *fp;
FILE *fp1;
char set[20];
int j,d,h,g,u=0;
int sum=0;
char delets='4';
if((fp=fopen("f4.txt","a+"))==NULL)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͷ<EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't open f4 file");
exit(0);
}
if((fp1=fopen("linshi.txt","a+"))==NULL)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͷ<EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't open linshi file");
exit(0);
}
while(delets=='4')
{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD>ʣ<EFBFBD>\n");
scanf("%s",set);
for(j=0;j<=10;j++)//<2F><><EFBFBD>ҵ<EFBFBD><D2B5>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
fscanf(fp,"%s\t%s\t%s\t",s[j].en,s[j].ch,s[j].ex);
if(strcmp(s[j].en,set)!=0)
{
fprintf(fp1,"%s\t",s[j].en);
d=sizeof(s[j].en);
fprintf(fp1,"%s\t",s[j].ch);
h=sizeof(s[j].ch);
fprintf(fp1,"%s\t",s[j].ex);
g=sizeof(s[j].ex);
u=d+g+h;
sum=sum+u;
}
else
{
rewind(fp);
fseek(fp,sum,0);
}
}
if(fclose(fp))//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC>ر<EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't close f4 file");
exit(0);
}
if(fclose(fp1))//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC>ر<EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't close linshi file");
exit(0);
}
remove("f4.txt");
rename("linshi.txt","f4.txt");
printf("\nɾ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>\n");
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>,<2C><><EFBFBD>ز˵<D8B2><CBB5><EFBFBD><EFBFBD><EFBFBD>#<23><>,<2C>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n\n");
delets=getch();
}
if(delets=='#')
{
printf("\n") ;
menus();
scanf("%d",&choice);
printf("\n") ;
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();break;
case 5:
modify();break;
case 0:
break;
}
}
}
//<2F>޸ĵ<DEB8><C4B5><EFBFBD><EFBFBD><EFBFBD>Ϣ
void modify()
{
int choice;
int i=0,g=1;//chooses<65><73><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>g<EFBFBD><67><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
int k,h,j;
char choose='5';
int size_y,size_z,size_l;
int len_y,len_z,len_l;
char x[100]; //<2F><><EFBFBD>Ҵ<EFBFBD><D2B4>󵥴<EFBFBD>
char y[100]; //<2F><>ȷӢ<C8B7><D3A2><EFBFBD><EFBFBD>ʽ
char z[100]; //<2F><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
char l[100]; //<2F><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>
while(choose=='5')
{
if((fp=fopen("f4.txt","r+"))==NULL)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͷ<EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't open file");
exit(0);
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>޸ĵĵ<EFBFBD><EFBFBD><EFBFBD>Ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ:");
scanf("%s",x);
for(i=0;i<10;i++)//<2F><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Ӣ<EFBFBD><D3A2><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
fscanf(fp,"%s\t%s\t%s\t",s[i].en,s[i].ch,s[i].ex);
if(strcmp(s[i].en,x)==0)
{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>Ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ:");
scanf("%s",y);
size_y=sizeof(s[i].en);
//len_y=strlen(y);
fseek(fp, 0, SEEK_SET); //ָ<><D6B8><EFBFBD>ع<EFBFBD>
k=fprintf(fp,"%s\t",y);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ:");
scanf("%s",z);
size_z=strlen(s[i].ch);
//len_z=strlen(z);
h=fprintf(fp,"%s\t",z);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%s",l);
size_l=strlen(s[i].ex);
//len_l=strlen(l);
j=fprintf(fp,"%s\t",l);
if(j&&h&&k)
printf("\n<EFBFBD>޸ijɹ<EFBFBD><EFBFBD><EFBFBD>\n");
else
{
printf("\n<EFBFBD>޸IJ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
printf("û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>\n");
}
}
}
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز˵<D8B2><CBB5><EFBFBD>ѡ<EFBFBD><D1A1># <20><>:");
scanf("%d",&choose);
if(fclose(fp))//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC>ر<EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't close file");
exit(0);
}
}
if(choose=='5')
{
printf("\n") ;
menus();
scanf("%d",&choice);
printf("\n") ;
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();break;
case 5:
modify();break;
case 0:
break;
}
}
}
//ϵͳ<CFB5>˵<EFBFBD>
void menus()
{
printf("\n");
printf(" *********************************************************\n");
printf(" # #\n");
printf(" # <20><>ѡ<EFBFBD><D1A1>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1> #\n");
printf(" # #\n");
printf(" *********************************************************\n");
printf(" # #\n");
printf(" # 0.<2E>˳<EFBFBD> 1.<2E><><EFBFBD><EFBFBD><EBB5A5> #\n");
printf(" # #\n");
printf(" # 2.<2E><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD> 3.<2E><><EFBFBD><EFBFBD> #\n");
printf(" # #\n");
printf(" # 4.ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 5.<2E>޸ĵ<DEB8><C4B5><EFBFBD> #\n");
printf(" # #\n");
printf(" *********************************************************\n");
printf("\n");
}
int main()
{
int choice;
printf("\n") ;
menus();
scanf("%d",&choice);
printf("\n") ;
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();break;
case 5:
modify();break;
case 0:
break;
}
return 0;
}