改好的,你看下(可以编译运行,逻辑上没看),主要是要养成良好的排版习惯(}位置不对)//////////////////////////////////////////////////////////////////////////23908578934563465345238975798345934////3458234905734905734257824532////防重复//345734895746757980////////////////////////////////////////////////////////////////#include<stdio.h>#include<string.h>intworsNumber=0;typedefstructdic{charword[20];charcn[80];}data;datadictionarySql[9000];intsearchWord(charword[20]);//先声明后使用intsearchCn(charcn[80]);voidsaveSql();intloadSql(data*sql,charpath[100]){inti=0;FILE*fp=NULL;fp=fopen("dictionary.txt","r");while(fscanf(fp,"%s\t%s",(sql+i)->word,(sql+i)->cn)!=EOF){i++;}fclose(fp);printf("共计%d个单词数据\n",i);printf("单词加载完毕,请输入指令进行操作:\n");return(i);}voidprintAction(){printf("1.英译汉\t|\n");printf("2.汉译英\t|\n");printf("3.添加单词数据\t|\n");printf("4.删除单词数据\t|\n");printf("5.修正单词数据\t|\n");printf("0.退出程序\t|\n");}voiddealAction(intaction){if(action==1){charword[20];intpos;printf("请您输入要查询的单词:");scanf("%s",word);pos=searchWord(word);if(pos!=-1)printf("单词\'%s\'的中文意思是:%s\n",word,dictionarySql[pos].cn);elseprintf("对不起,没有找到您所需要的单词\n");}elseif(action==2){intpos;charcn[80];printf("请您输入汉语词意(关键词即可):");scanf("%s",cn);pos=searchCn(cn);if(pos!=-1)printf("该翻译的英语单词是:%s\n",dictionarySql[pos].word);elseprintf("对不起,没有找到您所需要的翻译\n");}elseif(action==3){charword[20];charcn[80];printf("请您输入要补充的单词:");scanf("%s",word);strcpy(dictionarySql[worsNumber].word,word);printf("请您输入该单词汉语翻译:");scanf("%s",cn);strcpy(dictionarySql[worsNumber].cn,cn);worsNumber++;saveSql();printf("补充单词完成\n");}elseif(action==4){charword[50];intpos;//单词位置printf("请输入您要删除的单词:");scanf("%s",word);pos=searchWord(word);if(pos!=-1){chara[5]="#";strcpy(dictionarySql[pos].cn,a);strcpy(dictionarySql[pos].word,a);saveSql();printf("已经删除该单词\n");}elseprintf("对不起,没有找到您所需要的单词\n");}elseif(action==5){charword[50];intpos;//单词位置printf("请输入您要修正的单词:");scanf("%s",word);pos=searchWord(word);if(pos!=-1){printf("请输入单词汉语翻译:");charcn[60];scanf("%s",cn);strcpy(dictionarySql[pos].cn,cn);saveSql();printf("已经修正该单词翻译。\n");}elseprintf("对不起,没有找到您所需要的单词\n");}}intsearchWord(charword[20]){intlow,mid,high;low=0;high=worsNumber;while(low<=high){mid=(low+high)/2;if(strcmp(dictionarySql[mid].word,word)>0)high=mid-1;elseif(strcmp(dictionarySql[mid].word,word)<0)low=mid+1;else{returnmid;}}inti=0;for(i=0;i<worsNumber;i++){if(strcmp(dictionarySql[i].word,word)==0)returni;}return-1;}//}位置错了intsearchCn(charcn[80]){inti=0;for(i=0;i<worsNumber;i++){if(strstr(dictionarySql[i].cn,cn)!=NULL)returni;}return-1;}//}位置错了voidsaveSql(){FILE*fp=NULL;fp=fopen("dictionary.txt","w");inti=0;for(i=0;i<worsNumber;i++){if(dictionarySql[i].word[0]!='#'){fprintf(fp,"%s\t%s\n",dictionarySql[i].word,dictionarySql[i].cn);}}fclose(fp);}intmain(){worsNumber=loadSql(dictionarySql,"dictionary.txt");intaction=-1;while(action!=0){printAction();scanf("%d",&action);dealAction(action);}return0;}