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.
370 lines
7.4 KiB
370 lines
7.4 KiB
#include"stdio.h"
|
|
#include"stdlib.h"
|
|
#include"string.h"
|
|
#include<conio.h>
|
|
#include<windows.h>
|
|
#define FILENAME "翻译文档31.txt"
|
|
#define shoucanjia "收藏夹56.txt"
|
|
#define FILENAME1 "1.txt"
|
|
struct word//定义结构体
|
|
{
|
|
char chinese[100];
|
|
char english[100];
|
|
char mean[100];
|
|
char shuxing[100];
|
|
};
|
|
|
|
void color(short x) //自定义函根据参数改变颜色
|
|
|
|
{
|
|
|
|
if(x>=0 && x<=15)//参数在0-15的范围颜色
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); //只有一个参数,改变字体颜色
|
|
|
|
else//默认的颜色白色
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
|
|
|
|
}
|
|
|
|
|
|
FILE *FP;//定义文本指针
|
|
FILE *fileopen(char FileName[])//打开文档
|
|
{
|
|
FILE *fp;
|
|
if((fp=fopen(FileName,"rb"))==NULL)
|
|
{
|
|
color(4); printf("NO");
|
|
}
|
|
fp=fopen(FileName,"ab+");
|
|
}
|
|
|
|
void fileclose(FILE *fp)//关闭文档
|
|
{
|
|
if(fclose(fp)!=NULL)
|
|
{
|
|
color(4); printf("close defit");
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
void shoucan(word temp)//收藏的单词
|
|
{
|
|
FP=fileopen(shoucanjia);
|
|
printf("\n%s %s %s %s ",temp.english,temp.chinese,temp.mean,temp.shuxing);
|
|
printf("收藏成功!!!");
|
|
fwrite(&temp,sizeof(temp),1,FP);
|
|
fileclose(FP);
|
|
|
|
}
|
|
|
|
void findlike()//查看收藏夹
|
|
{
|
|
system("cls");
|
|
FILE *fp;
|
|
if((fp=fopen(shoucanjia,"rb"))==NULL)
|
|
{
|
|
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:");
|
|
printf("输入单词:");
|
|
printf("退格:退格查看所有单词\n");
|
|
while(1)
|
|
{
|
|
int m=0;
|
|
n=0;
|
|
printf("\n\n\n返回上一级按空格键 ");
|
|
if(i!=0)
|
|
printf("退格:退后一个单词");
|
|
char c=getch();
|
|
system("cls");
|
|
if(c==32)
|
|
break;
|
|
printf("输入单词:");
|
|
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;
|
|
if((fp=fopen(shoucanjia,"rb"))==NULL)
|
|
{
|
|
printf("OPEN DEFIT");
|
|
}
|
|
|
|
while(fread(&temp,sizeof(word),1,fp))
|
|
{
|
|
|
|
|
|
if(strcmp(temp.english,tempenglish)==0)
|
|
{
|
|
printf("\n中文是:%s 英文是:%s 例句是:%s 属性是:%s\n",temp.chinese,temp.english,temp.mean,temp.shuxing);
|
|
n=0;
|
|
}
|
|
else
|
|
{
|
|
char *res = strstr(temp.english,tempenglish);
|
|
if(res == NULL)
|
|
{
|
|
n=2;
|
|
}
|
|
else
|
|
{
|
|
printf("\n你要查找的可能是:\n中文是:%s 英文是:%s 例句是:%s 属性是:%s\n",temp.chinese,temp.english,temp.mean,temp.shuxing);
|
|
m=1;
|
|
}
|
|
}
|
|
}
|
|
fileclose(fp);
|
|
if(n==2&&m==0)
|
|
printf("\n您没有收藏此单词!");
|
|
}
|
|
fileclose(fp);
|
|
}
|
|
|
|
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))//关闭文件并防止文件关闭失败。
|
|
{
|
|
printf("cann't close linshi file");
|
|
}
|
|
fclose(fp1);
|
|
if(fclose(fp))//关闭文件并防止文件关闭失败。
|
|
{
|
|
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("删除成功!");
|
|
else
|
|
printf("删除失败,词库没有此单词!");
|
|
if(m==0)
|
|
printf("词库为空!");
|
|
|
|
}
|
|
void change()//英汉翻译
|
|
{
|
|
system("cls");
|
|
char tempenglish[100];
|
|
for(int z=0;z<=100;z++)
|
|
tempenglish[z]=0;
|
|
char *res;
|
|
word temp;
|
|
int n=0,i=0,m=0;
|
|
printf(" 输入单词:");
|
|
printf("退格查看所有单词。");
|
|
while(1)
|
|
{
|
|
m=0;
|
|
n=0;
|
|
printf("\n\n\n返回上一级按空格键 ");
|
|
if(i!=0)
|
|
printf("退格:退后一个单词");
|
|
char c=getch();
|
|
stop: system("cls");
|
|
if(c==32)
|
|
break;
|
|
printf(" 输入单词:");
|
|
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;
|
|
if((fp=fopen(FILENAME,"rb+"))==NULL)
|
|
{
|
|
printf("OPEN DEFIT");
|
|
}
|
|
|
|
while(fread(&temp,sizeof(word),1,fp))
|
|
{
|
|
if(strcmp(temp.english,tempenglish)==0)
|
|
{
|
|
printf("\n中文是:%s 英文是:%s 例句是:%s 属性是:%s\n",temp.chinese,temp.english,temp.mean,temp.shuxing);
|
|
printf("\n-------按1收藏");
|
|
printf("\n-------按0修改");
|
|
printf("\n-------按其他键继续查找");
|
|
c=getch();
|
|
if(c==49)
|
|
{
|
|
shoucan(temp);//收藏单词
|
|
}
|
|
else if(c==48)//修改单词
|
|
{
|
|
printf("\n修改后的英文:");
|
|
scanf("%s",temp.english);
|
|
printf("修改后的意思:");
|
|
scanf("%s",temp.chinese);
|
|
printf("例子:");
|
|
fflush(stdin);
|
|
gets(temp.mean);
|
|
printf("属性:");
|
|
scanf("%s",temp.shuxing);
|
|
printf("%s %s %s %s ",temp.english,temp.chinese,temp.mean,temp.shuxing);
|
|
fseek(fp,-sizeof(word),SEEK_CUR);
|
|
|
|
fwrite(&temp,sizeof(temp),1,fp);
|
|
printf("修改成功!!!");
|
|
//fileclose(fp);
|
|
break;
|
|
}
|
|
else
|
|
goto stop;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
char *res = strstr(temp.english,tempenglish);
|
|
if(res != NULL)
|
|
{
|
|
printf("\n你要查找的可能是:\n中文是:%s 英文是:%s 例句是:%s 属性是:%s\n",temp.chinese,temp.english,temp.mean,temp.shuxing);
|
|
m=1;
|
|
}
|
|
else
|
|
{
|
|
n=2;
|
|
}
|
|
}
|
|
}
|
|
fileclose(fp);
|
|
if(n==2&&m==0)
|
|
{
|
|
printf("\n没有这个单词");
|
|
}
|
|
}
|
|
}
|
|
|
|
void putinto()//插入词库
|
|
{
|
|
color(2);
|
|
stop: printf("\n");
|
|
FP=fileopen(FILENAME);
|
|
word temp;
|
|
printf("你想写入的单词:");
|
|
scanf("%s",temp.english);
|
|
printf("此单词的中文:");
|
|
scanf("%s",temp.chinese);
|
|
printf("例句:");
|
|
fflush(stdin);
|
|
gets(temp.mean);
|
|
printf("属性:");
|
|
scanf("%s",temp.shuxing);
|
|
fwrite(&temp,sizeof(temp),1,FP);
|
|
printf("添加成功!!!!!");
|
|
fileclose(FP);
|
|
printf("继续输入Y/退出N");
|
|
char b=getch();
|
|
if(b==89||b==121)
|
|
goto stop;
|
|
}
|
|
|
|
|
|
int caidan()//菜单
|
|
{
|
|
int choose=1;
|
|
|
|
while(choose!=0)
|
|
{
|
|
color(1);
|
|
printf("\n");
|
|
printf(" *********************************************************\n");
|
|
printf(" # #\n");
|
|
printf(" # 请选择系统功能选项 #\n");
|
|
printf(" # #\n");
|
|
printf(" *********************************************************\n");
|
|
printf(" # #\n");
|
|
printf(" # 0.退出 1.输入单词 #\n");
|
|
printf(" # #\n");
|
|
printf(" # 2.查找单词 3.清屏 #\n");
|
|
printf(" # #\n");
|
|
printf(" # 4.查看收藏夹 5.删除单词 #\n");
|
|
printf(" *********************************************************\n");
|
|
printf("\n");
|
|
scanf("%d",&choose);
|
|
switch(choose)
|
|
{
|
|
case 0:return 0;break;
|
|
case 1:putinto();break;
|
|
case 2:change();break;
|
|
case 3:system("cls");break;
|
|
case 4:findlike();break;
|
|
case 5:shanchu();break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main()//主函数
|
|
{
|
|
caidan();
|
|
}
|
|
|