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.

285 lines
6.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();
FILE *fp;
int num=0;
struct word
{
char en[100];
char ch[100];
char ex[100];
}s[200];
void clean()
{
system("cls");
}
void add()//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
{
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=='#')
{
menus();
scanf("%d",&choice);
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();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);
}
}
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=='#')
{
menus();
scanf("%d",&choice);
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();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);
}
}
//ɾ<><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>\n\n<EFBFBD><EFBFBD><EFBFBD>ز˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>#<23><>\n\n<EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n\n");
delets=getch();
}
if(delets=='#')
{
menus();
scanf("%d",&choice);
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();break;
case 0:
break;
}
}
}
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> #\n");
printf(" # #\n");
printf(" *********************************************************\n");
printf("\n");
}
int main()
{
int choice;
menus();
scanf("%d",&choice);
switch(choice)
{
case 1:
add();break;
case 2:
finds();break;
case 3:
clean();break;
case 4:
delet();break;
case 0:
break;
}
return 0;
}