16,471
社区成员
发帖
与我相关
我的任务
分享
typedef struct tagLAN
{
char En[20]; //英文字母
char Cn[20]; //中文解释
struct tagLAN *next;
}LAN,*LPLAN;
LPLAN CreatList()
{
LPLAN Head=(LPLAN)malloc(sizeof(LAN));
memcpy(Head->En,"QIAN",20);
memcpy(Head->Cn,"你大爷我",20);
Head->next=NULL;
return Head;
}
void LoadData(LPLAN L)
{
LPLAN pCur;
char buf[40];
FILE *fp;
fp=fopen("D:\\字典.DAT","rb");
if(NULL==fp)
{
printf("数据文件找不到\n");
return;
}
pCur=L;
while(1)
{
fread(buf,40,1,fp);
if(feof(fp) break;
LPLAN temp=(LPLAN)malloc(sizeof(LAN));
memcpy(temp,buf,40);
pCur->next=temp;
pCur=pCur->next;
}
fclose(fp);
}
void main()
{
LPLAN List,Sel;
char key[20];
BOOL EXIT=false;
List=CreatList();
while(EXIT)
{
memset(key,0,20);
printf("\n请输入关键词:");
scanf("%s",&key);
if(memcmp(key,"Bay",3))
EXIT=true;
else
{
Sel=List;
while(Sel)
{
if(!memcmp(key,Sel->En,3)
{
printf("\n相关的翻译是:%s",Sel->Cn);
break;
}
if(!memcmp(key,Sel->Cn,3)
{
printf("\n相关的翻译是:%s",Sel->En);
break;
}
}
if(!Sel) printf("\n相关的翻译是:无对应词条!");
}
}
}
void main()
{
FILE *fp;
char buf1[20];
char buf2[20];
fp=fopen("d:\\字典.dat","wb");
printf("\n输入 QUIT 退出!\n");
while(1)
{
printf("\n输入英文词条:");
scanf("%s",buf1);
if(!memcmp(buf1,"QUIT",4)) break;
printf("\n输入中文词条:");
scanf("%s",buf2);
if(!memcmp(buf2,"QUIT",4)) break;
fread(buf1,20,1,fp);
fread(buf2,20,1,fp);
}
fclose(fp);
}