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.
ai_12/实时输入输出的翻译.cpp

366 lines
7.4 KiB

6 years ago
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
6 years ago
#include<conio.h>
6 years ago
#include<windows.h>
6 years ago
#define FILENAME "<22><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>31.txt"
#define shoucanjia "<22>ղؼ<D5B2>56.txt"
6 years ago
#define FILENAME1 "1.txt"
6 years ago
struct word//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9>
6 years ago
{
char chinese[100];
char english[100];
6 years ago
char mean[100];
6 years ago
char shuxing[100];
};
6 years ago
void color(short x) //<2F>Զ<EFBFBD><D4B6><EFBFBD><E5BAAF><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫ
{
if(x>=0 && x<=15)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0-15<31>ķ<EFBFBD>Χ<EFBFBD><CEA7>ɫ
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); //ֻ<><D6BB>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
else//Ĭ<>ϵ<EFBFBD><CFB5><EFBFBD>ɫ<EFBFBD><C9AB>ɫ
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
6 years ago
6 years ago
FILE *FP;//<2F><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>ָ<EFBFBD><D6B8>
FILE *fileopen(char FileName[])//<2F><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
6 years ago
{
FILE *fp;
if((fp=fopen(FileName,"rb"))==NULL)
{
6 years ago
color(4); printf("NO");
6 years ago
}
fp=fopen(FileName,"ab+");
}
6 years ago
void fileclose(FILE *fp)//<2F>ر<EFBFBD><D8B1>ĵ<EFBFBD>
6 years ago
{
if(fclose(fp)!=NULL)
{
6 years ago
color(4); printf("close defit");
6 years ago
exit(0);
6 years ago
}
}
void shoucan(word temp)//<2F>ղصĵ<D8B5><C4B5><EFBFBD>
{
FP=fileopen(shoucanjia);
6 years ago
printf("\n%s %s %s %s ",temp.english,temp.chinese,temp.mean,temp.shuxing);
printf("<EFBFBD>ղسɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
6 years ago
fwrite(&temp,sizeof(temp),1,FP);
fileclose(FP);
}
6 years ago
void findlike()//<2F><EFBFBD>ղؼ<D5B2>
6 years ago
{
system("cls");
FILE *fp;
6 years ago
if((fp=fopen(shoucanjia,"rb"))==NULL)
6 years ago
{
printf("OPEN DEFIT");
}
char tempenglish[100];
for(int z=0;z<=100;z++)
tempenglish[z]=0;
char *res;
word temp;
int n=0,i=0;
printf("PLEAES INPUT ENGLISH:");
6 years ago
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>");
printf("<EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>\n");
6 years ago
while(1)
{
6 years ago
int m=0;
6 years ago
printf("\n\n\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD> ");
6 years ago
if(i!=0)
6 years ago
printf("<EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
char c=getch();
system("cls");
if(c==32)
break;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>");
if(c==8)
{
tempenglish[i-1]=0;
for(int j=0;j<i;j++)
{
printf("%c",tempenglish[j]);
}
i=i-1;
}
else{
tempenglish[i]=c;
for(int j=0;j<=i;j++)
printf("%c",tempenglish[j]);
i=i+1;
}
FILE *fp;
6 years ago
if((fp=fopen(shoucanjia,"rb"))==NULL)
6 years ago
{
printf("OPEN DEFIT");
}
while(fread(&temp,sizeof(word),1,fp))
{
if(strcmp(temp.english,tempenglish)==0)
{
6 years ago
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s Ӣ<><D3A2><EFBFBD><EFBFBD>:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s\n",temp.chinese,temp.english,temp.mean,temp.shuxing);
6 years ago
n=0;
}
else
{
char *res = strstr(temp.english,tempenglish);
if(res == NULL)
{
n=2;
}
else
{
6 years ago
printf("\n<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ҵĿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s Ӣ<><D3A2><EFBFBD><EFBFBD>:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s\n",temp.chinese,temp.english,temp.mean,temp.shuxing);
m=1;
6 years ago
}
}
}
fileclose(fp);
6 years ago
if(n==2&&m==0)
6 years ago
printf("\n<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>ղش˵<EFBFBD><EFBFBD>ʣ<EFBFBD>");
6 years ago
}
fileclose(fp);
}
6 years ago
void shanchu()
{
system("cls");
FILE *fp;
FILE *fp1;
word temp;
char c[100];
int n=0,m=0,sum=0,j=0;
if((fp=fopen(FILENAME,"rb"))==NULL)
{
printf("OPEN DEFIT");
}
if((fp1=fopen(FILENAME1,"wb+"))==NULL)
{
printf("OPEN DEFIT");
}
// scanf("%s",&sum);
scanf("%s",c);
while(fread(&temp,sizeof(word),1,fp))
{
if(strcmp(temp.english,c)!=0)
{
// printf("%s",temp.english);
m=1;
// j=sizeof(word);
// sum=sum+j;
// printf("1");
fwrite(&temp,sizeof(temp),1,fp1);
}
else
{
n=1;
// rewind(fp);
// fseek(fp,sum,0);
}
}
if(fclose(fp1))//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC>ر<EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't close linshi file");
}
fclose(fp1);
if(fclose(fp))//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ļ<EFBFBD><C4BC>ر<EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>
{
printf("cann't close this file");
}
remove(FILENAME);
if (rename(FILENAME1,FILENAME) == 0)
printf("Renamed %s to %s.\n",FILENAME1,FILENAME);
else
perror("rename");
if(n==1&&m==1)
printf("ɾ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>");
else
printf("ɾ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>,<2C>ʿ<EFBFBD>û<EFBFBD>д˵<D0B4><CBB5>ʣ<EFBFBD>");
}
6 years ago
void change()//Ӣ<><D3A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
6 years ago
{
system("cls");
char tempenglish[100];
for(int z=0;z<=100;z++)
tempenglish[z]=0;
char *res;
word temp;
6 years ago
int n=0,i=0,m=0;
6 years ago
printf(" <20><><EFBFBD><EFBFBD>ʣ<EFBFBD>");
6 years ago
printf("<EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>ʡ<EFBFBD>");
6 years ago
while(1)
{
6 years ago
m=0;
6 years ago
printf("\n\n\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD> ");
6 years ago
if(i!=0)
6 years ago
printf("<EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
char c=getch();
stop: system("cls");
if(c==32)
break;
printf(" <20><><EFBFBD><EFBFBD>ʣ<EFBFBD>");
if(c==8)
{
tempenglish[i-1]=0;
for(int j=0;j<i;j++)
{
printf("%c",tempenglish[j]);
}
i=i-1;
}
else{
tempenglish[i]=c;
for(int j=0;j<=i;j++)
printf("%c",tempenglish[j]);
i=i+1;
}
FILE *fp;
6 years ago
if((fp=fopen(FILENAME,"rb+"))==NULL)
{
printf("OPEN DEFIT");
}
6 years ago
while(fread(&temp,sizeof(word),1,fp))
6 years ago
{
6 years ago
if(strcmp(temp.english,tempenglish)==0)
{
6 years ago
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s Ӣ<><D3A2><EFBFBD><EFBFBD>:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s\n",temp.chinese,temp.english,temp.mean,temp.shuxing);
6 years ago
printf("\n-------<2D><>1<EFBFBD>ղ<EFBFBD>");
printf("\n-------<2D><>0<EFBFBD>޸<EFBFBD>");
printf("\n-------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
c=getch();
if(c==49)
{
shoucan(temp);//<2F>ղص<D5B2><D8B5><EFBFBD>
}
else if(c==48)//<2F>޸ĵ<DEB8><C4B5><EFBFBD>
{
printf("\n<EFBFBD>޸ĺ<EFBFBD><EFBFBD><EFBFBD>Ӣ<EFBFBD><EFBFBD>:");
scanf("%s",temp.english);
printf("<EFBFBD>޸ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˼:");
scanf("%s",temp.chinese);
6 years ago
printf("<EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>");
6 years ago
fflush(stdin);
gets(temp.mean);
6 years ago
printf("<EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>");
scanf("%s",temp.shuxing);
6 years ago
printf("%s %s %s %s ",temp.english,temp.chinese,temp.mean,temp.shuxing);
6 years ago
fseek(fp,-sizeof(word),SEEK_CUR);
fwrite(&temp,sizeof(temp),1,fp);
printf("<EFBFBD>޸ijɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
//fileclose(fp);
break;
}
else
goto stop;
6 years ago
6 years ago
}
6 years ago
else
6 years ago
{
6 years ago
char *res = strstr(temp.english,tempenglish);
if(res != NULL)
{
printf("\n<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ҵĿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s Ӣ<><D3A2><EFBFBD><EFBFBD>:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%s\n",temp.chinese,temp.english,temp.mean,temp.shuxing);
m=1;
}
else
{
n=2;
}
6 years ago
}
}
fileclose(fp);
6 years ago
if(n==2&&m==0)
6 years ago
{
6 years ago
printf("\nû<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
6 years ago
}
}
void putinto()//<2F><><EFBFBD><EFBFBD><EFBFBD>ʿ<EFBFBD>
{
6 years ago
color(2);
6 years ago
stop: printf("\n");
FP=fileopen(FILENAME);
word temp;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD>ʣ<EFBFBD>");
scanf("%s",temp.english);
printf("<EFBFBD>˵<EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>");
scanf("%s",temp.chinese);
6 years ago
printf("<EFBFBD><EFBFBD><EFBFBD>");
6 years ago
fflush(stdin);
gets(temp.mean);
6 years ago
printf("<EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>");
scanf("%s",temp.shuxing);
fwrite(&temp,sizeof(temp),1,FP);
printf("<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
fileclose(FP);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Y/<2F>˳<EFBFBD>N");
char b=getch();
6 years ago
if(b==89||b==121)
6 years ago
goto stop;
}
6 years ago
int caidan()//<2F>˵<EFBFBD>
6 years ago
{
int choose=1;
6 years ago
6 years ago
while(choose!=0)
{
6 years ago
color(1);
6 years ago
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");
6 years ago
printf(" # #\n");
printf(" # 4.<2E><EFBFBD>ղؼ<D5B2> 5.ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD> #\n");
6 years ago
printf(" *********************************************************\n");
printf("\n");
6 years ago
scanf("%d",&choose);
6 years ago
switch(choose)
{
case 0:return 0;break;
case 1:putinto();break;
case 2:change();break;
case 3:system("cls");break;
case 4:findlike();break;
6 years ago
case 5:shanchu();break;
6 years ago
}
}
}
int main()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
caidan();
}
6 years ago