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.

173 lines
4.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<string.h>
#include<cstdlib>
#include<windows.h>
#include<ctype.h>
void Search(char *s)
{
freopen("dictionary.txt","r",stdin);
char a[100],b[100];
int ok=1;
while(scanf("%s %s",a,b)!=EOF)
{
if(strcmp(s,a)==0)
{printf("%s %s",a,b);ok=0;break;}
}
if(ok)printf("Not Found!");
putchar('\n');
freopen("CON","r",stdin); //切换到从控制台输入数据
freopen("CON","w",stdout); //切换到到控制台输出数据
}
void Add(char *s,char* a)
{
freopen("dictionary.txt","a+",stdout);
printf("%s %s\n",s,a);
freopen("CON","r",stdin);
freopen("CON","w",stdout);
}
void Change(char* s1,char* s2)
{
char a[100],b[100];
char s[1000][50];
int len,i=0,j;
memset(s,0,sizeof(a));
freopen("dictionary.txt","r",stdin);
while(scanf("%s%s",a,b)!=EOF)
{
if(strcmp(s1,a)!=0)
strcat(s[i],a);
else if(strcmp(s1,a)==0)
strcat(s[i],s2);
len=strlen(s[i]);s[i][len]=' ';
strcat(s[i++],b);
}
freopen("dictionary.txt","w",stdout);
for(j=0;j<i;j++)
{
if(j!=i-1)printf("%s\n",s[j]);
else printf("%s",s[j]);
}
freopen("CON","r",stdin);
freopen("CON","w",stdout);
}
void Delete(char *s)
{
char a[300][20],b[100],c[100];int i,ok=0,p=0;
memset(a,0,sizeof(a));
freopen("dictionary.txt","r",stdin);
while(scanf("%s%s",b,c)!=EOF)
{
//getchar();
if(strcmp(b,s)!=0)
{
strcat(a[p],b);
int len=strlen(a[p]);
a[p][strlen(a[p])]=' ';
strcat(a[p],c);
p++;
}
}
freopen("dictionary.txt","w",stdout);
for(i=0;i<p;i++)
{
printf("%s\n",a[i]);
}
freopen("CON","r",stdin);
freopen("CON","w",stdout);
}
void print()
{
char a[100];int cout=0;
freopen("dictionary.txt","r",stdin);
while(scanf("%s",a)!=EOF)
{
cout++;
for(int i=0;i<strlen(a);i++)
putchar(a[i]);
if(cout%2==0)putchar('\n');
else printf(" ");
}
freopen("CON","r",stdin); //切换到从控制台输入数据
freopen("CON","w",stdout);
}
int main()
{
char a[100],b[100];
int op,x;
printf("\t\t\t\t/******** 电子英汉查询系统 *********/\n");
printf("\n\n");
printf("\t\t\t\t/********* 搜查单词请按1 *********/\n");
printf("\t\t\t\t/********* 增加单词请按2 *********/\n");
printf("\t\t\t\t/********* 删除单词请按3 *********/\n");
printf("\t\t\t\t/********* 替换单词请按4 *********/\n");
printf("\t\t\t\t/********* 显示词库请按5 *********/\n\n\n");
printf("如果您在进行一个操作后,又想进行其它操作,请根据所给提示退出当前操作");
printf("\n\n\n");
printf("请输入您想输入的操作:\n");
while(1)
{
printf("**************************************************\n");scanf("%d",&op);//printf("**************************************************\n");
if(op==1)
{
while(1)
{
printf("**************************************************\n");
printf("输入你想要查询的单词\n");
printf("**************************************************\n");scanf("%s",a);
Search(a);//
printf("**************************************************\n");
printf("再次输入按1返回总菜单按2\n");
printf("**************************************************\n");scanf("%d",&x);
if(x==1)continue;
else { break;}
}
}
else if(op==2)
{
while(1)
{printf("**************************************************\n");
printf("请输入你想增加的单词和释义\n");
printf("**************************************************\n");
scanf("%s%s",a,b);
Add(a,b);
printf("**************************************************\n");printf("再次输入按1返回总菜单按2\n");printf("**************************************************\n");
scanf("%d",&x);
if(x==1)continue;
else { break;}
}
}
else if(op==3)
{
while(1)
{
printf("**************************************************\n");printf("输入你想删除的单词\n");
printf("**************************************************\n");scanf("%s",a);Delete(a);
printf("**************************************************\n");printf("再次输入按1返回总菜单按2\n");
printf("**************************************************\n");scanf("%d",&x);
if(x==1)continue;
else { break;}
}
}
else if(op==4)
{
while(1)
{
printf("**************************************************\n");printf("按顺序输入替换前的单词和替换后的单词\n");
printf("**************************************************\n");scanf("%s%s",a,b);Change(a,b);
printf("**************************************************\n");printf("再次输入按1返回总菜单按2\n");
printf("**************************************************\n");scanf("%d",&x);
if(x==1)continue;
else { break;}
}
}
else if(op==5)
{
printf("**************************************************\n");printf("打印单词库\n");
printf("**************************************************\n");print();
}
} return 0;
}