#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#define MAXSIZE 8000
typedef struct
{
char chinese[50];
char english[25];
}dict;
dict dictionary[MAXSIZE] = { 0 };
int number = 0;
void print_jm()
{
printf("*********************************************\n");
printf("*************欢迎使用英汉互译词典************\n");
printf("**1、英译汉**********************************\n");
printf("**2、汉译英**********************************\n");
printf("**3、收藏单词功能****************************\n");
printf("**4、删除单词********************************\n");
printf("**5、显示所有单词及释义**********************\n");
printf("**6、修改单词及释义**************************\n");
printf("**7、退出************************************\n");
}
void find_chinese(char *English)
{
int i;
for (i=0; i <= number; i++)
{
if (strcmp(English, dictionary[i].english)==0)
{
printf("%s %s\n", dictionary[i].english, dictionary[i].chinese);
break;
}
else if (i == number)
{
printf("没查到该单词!\n");
}
}
}
void find_english(char *Chinese)
{
int i;
for (i = 0; i <= number; i++)
{
if(strstr(dictionary[i].chinese, Chinese))
{
printf("%s %s\n", dictionary[i].english, dictionary[i].chinese);
break;
}
if(i==number)
{
printf("搜索不到该单词!\n");
}
}
}
void collect(char *English, char *Chinese)
{
FILE *fc = fopen("D:/dict.txt", "a");
if (fc == NULL)
{
perror("collect file");
exit(1);
}
fprintf(fc, "%s %s\n", English, Chinese);
printf("收藏成功!");
fclose(fc);
strcpy(dictionary[number-1].english, English);
strcpy(dictionary[number-1].chinese, Chinese);
number++;
}
void del_word(char *English)
{
int i,j;
FILE *fd = fopen("D:/dict.txt", "w+");
if (fd == NULL)
{
perror("del file");
exit(1);
}
for (i = 0; i <= number; i++)
{
if (strcmp(English, dictionary[i].english) == 0)
{
printf("找到该单词位置\n");
for (j = i; j < number; j++)
{
strcpy(dictionary[j].english, dictionary[j + 1].english);
strcpy(dictionary[j].chinese, dictionary[j + 1].chinese);
}
number--;
}
}
for (i = 0; i < number-1; i++)
{
fprintf(fd, "%s %s\n", dictionary[i].english, dictionary[i].chinese);
}
fclose(fd);
printf("删除成功\n");
}
void check(char *word,char *English, char *Chinese)
{
int i, j;
char ch;
FILE *fch = fopen("D:/dict.txt", "w+");
if (fch == NULL)
{
perror("del file");
exit(1);
}
for (i = 0; i <= number; i++)
{
if (strcmp(word, dictionary[i].english) == 0)
{
printf("找到该单词位置\n");
strcpy(dictionary[i].english, English);
strcpy(dictionary[i].chinese, Chinese);
}
}
for (i = 0; i < number - 1; i++)
{
fprintf(fch, "%s %s\n", dictionary[i].english, dictionary[i].chinese);
}
fclose(fch);
printf("修改成功\n");
}
int main()
{
int choose=0;
int i ;
char Chinese[50] = { 0 };
char English[26] = { 0 };
char word[26] = { 0 };
FILE *fp;
if ((fp = fopen("D:/dict.txt", "r")) == NULL)
{
perror("file");
exit(1);
}
//将文件数据保存到结构体(缓存)
while (!feof(fp))
{
fscanf(fp, "%s %s", dictionary[number].english, dictionary[number].chinese);
number++;
}
while (1)
{
system("cls");
print_jm();
scanf("%d", &choose);
fflush(stdin);
if (choose == 7)
{
exit(1);
}
else if(choose==1)
{
printf("请输入你要查询的单词:>");
scanf("%s", English);
fflush(stdin);
find_chinese(English);
system("pause");
}
else if (choose == 2)
{
printf("请输入要翻译的含义:>");
scanf("%s", Chinese);
fflush(stdin);
find_english(Chinese);
system("pause");
}
else if (choose == 3)
{
printf("请输入需收藏的单词:\n");
scanf("%s", English);
fflush(stdin);
printf("请输入收藏单词的释义:\n");
scanf("%s", Chinese);
fflush(stdin);
collect(English, Chinese);
system("pause");
}
else if (choose == 4)
{
printf("请输入需要删除的单词:\n");
scanf("%s", English);
fflush(stdin);
del_word(English);
system("pause");
}
else if (choose == 5)
{
i = 0;
while (i <= number)
{
printf("%s %s\n", dictionary[i].english, dictionary[i].chinese);
i++;
}
system("pause");
}
else if (choose == 6)
{
printf("请输入需要修改的单词:\n");
scanf("%s", word);
fflush(stdin);
printf("请输入修改的单词:\n");
scanf("%s", English);
fflush(stdin);
printf("请输入需要修改单词的释义:\n");
scanf("%s", Chinese);
fflush(stdin);
check(word,English, Chinese);
system("pause");
}
fclose(fp);
}
return 0;
}
最后必须是单独一行。
account n.账,账目;
act n.行为,行动,(法案,戏剧、歌剧等的)一幕
addition n.增加,附加物,加,加法
adjustment n.调整
advertisement adv.广告
agreement n.同意,一致,协议
air n.空气,旋律,气氛,态度
amount n.数量,总额vi.总计,等于
amusement n.娱乐,消遣
animal n.动物,兽,牲畜
answer vt.&vi.答复
apparatus n.装置,器具,机构,组织
approval n.批准,认可,同意,赞同
argument n.辩论,争论,论点(据),理由
art adj.美术(品)的,艺术(品)的n.艺术,技术,阴谋,美术
attack vi.攻击,进攻,抨击
attempt vt.试图
attention n.注意(力),关心,立正
attraction n.吸引,吸引力,有吸引力的人或事物
authority n.权威;权力;当局