我现场编了一个
/****************************灵灵猴速查词典2.0版****************************
**************************作者:阮迪申 2011年3月9日************************
**********************版权:兴化灵灵猴网 所有权利保留**********************
*************************新版本诞生于2011年3月10日**************************
******************新特性有:增加了3个功能:退出,清屏和列词头**************/
#include
#include
#include
#include
void main()
{
char a[20],str[20],res[60],ch;
int len,i;
FILE*fp;
if((fp=fopen("灵灵猴英汉速查词典.txt","r"))==NULL)
{
printf("找不到\"灵灵猴英汉速查词典.txt\",请确认该文件保存在本程序目录下。\n");
getch();
exit(1);
}
printf("欢迎使用灵灵猴英汉速查词典\n");
again:printf("请输入要查询的单词:");
scanf("%s",a);
len=strlen(a);
if(len>=20)
{
printf("输入的字符过多,请重新输入:\n");
goto again;
}
/*单词查找*/
rewind(fp);
fgets(str,len+1,fp);
while(strcmp(str,a)!=0)
{
if(fgetc(fp)=='*')
{
printf("无法找到该单词。\n");
goto again;
}
for(;;)
{
if(fgetc(fp)=='\n')
break;
}
fgets(str,len+1,fp);
}
/*单词释义输出*/
fseek(fp,-(long)len,1);
for(i=0;(ch=fgetc(fp))!='\n';i++)
{
res[i]=ch;
}
res[i]='\0';
printf("%s\n",res);
/*查词完成后的选项*/
next:printf("请选择:1.继续查词 2.清屏 3.列出以%s打头的所有单词 4.退出。\n",a);
switch(getch())
{
case'1':goto again;
case'2':system("CLS");goto next;
case'3':printf("%s\n",res);
{
fgets(str,len+1,fp);
while(strcmp(str,a)==0)
{
fseek(fp,-(long)len,1);
for(i=0;(ch=fgetc(fp))!='\n';i++)
{
res[i]=ch;
}
res[i]='\0';
printf("%s\n",res);
fgets(str,len+1,fp);
}
}goto next;
case'4':printf("感谢您的使用,再见,按任意键退出\n");getch();exit(1);
default:printf("输入有误,请重新输入\n");goto next;
}
}
取消
评论