单词库需要手动添加单词,一共有三个txt文档
文档格式如下
备注:必修严格按照格式来,否者则会显示不准确。
实现功能如下
查询单词:汉语查询英语英语查查询汉语
背诵模式:出现英语默写汉语,出现汉语默写英语
还有 错词背诵模式
查看全部单词
查看全部错词
移除一个错词
等等
全部代码如下:
#include#include#include#includevoid menu();void beidanci();void words();void lookcw(); void search();void movecc(); void beidancicw();int k=1;int main(){int w=0;while(k!=0){menu();}system("pause");return 0;}void words(){int i=0;typedef struct stu{int j;char yw[20];char zw[20];}dcb;dcb dcb_[1000];FILE *fp;fp=fopen("D:\\仿真单词本\\dancibenqb.txt","r");if(!fp){printf("打开失败!");exit(1);}fscanf(fp,"%d%s%s",&dcb_[i].j,dcb_[i].yw,dcb_[i].zw);while(!feof(fp)){i++;fscanf(fp,"%d%s%s",&dcb_[i].j,dcb_[i].yw,dcb_[i].zw);}fclose(fp);dcb_[i+1].j=0;i=0;printf("单词本的信息如下\n");while((dcb_[i].j)!=0){printf("%d %s %s\n",dcb_[i].j,dcb_[i].yw,dcb_[i].zw);i++;}system("pause");}void beidanci(){typedef struct stu{int j;char yw[20];char zw[20];}dcb;dcb dcb_[1000];typedef struct ct{int c;char Cyw[20];char Czw[20];}ctb;ctb ctb_[1000];FILE *fp;int i=0,count=0,q=0;int w=1,count1;char zwsr[20];fp=fopen("D:\\仿真单词本\\dancibenqb.txt","r");fscanf(fp,"%d%s%s",&dcb_[i].j,dcb_[i].yw,dcb_[i].zw);while(!feof(fp)){i++;fscanf(fp,"%d%s%s",&dcb_[i].j,dcb_[i].yw,dcb_[i].zw);}fclose(fp);fp=fopen("D:\\仿真单词本\\dancibencw.txt","r");fscanf(fp,"%d%s%s",&ctb_[q].c,ctb_[q].Cyw,ctb_[q].Czw);while(!feof(fp)){q++;fscanf(fp,"%d%s%s",&ctb_[q].c,ctb_[q].Cyw,ctb_[q].Czw);}count1=q;fclose(fp);dcb_[i+1].j=0;int m=0;printf("单词本的信息如下\n");while((dcb_[m].j)!=0){printf("%d %s %s\n",dcb_[m].j,dcb_[m].yw,dcb_[m].zw);m++;}count=m;int n;int sjs[50]={0};//随机数 srand(time(NULL));printf("请选择背单词的模式:\n\n1: 出现英语背诵翻译\n2: 出现汉字默写英语\n");int num,p=0;scanf("%d",&num);if(num==1){printf("请输入背单词的数量"); scanf("%d",&n);for(int i=0;i<n;i++){sjs[i]=rand()%count+1;}int c=0;int zw=0;for(int i1=0;i1<n;i1++){printf("%s\n",dcb_[sjs[i1]].zw);scanf("%s",zwsr);if(strcmp(zwsr,dcb_[sjs[i1]].yw)!=0){printf("背诵错误,已计入错题本!\n");fp=fopen("D:\\仿真单词本\\dancibencw.txt","a+");if(!fp){printf("打开失败");exit(1); }else {fprintf(fp,"%d %s %s\n",count1+1,dcb_[sjs[i1]].yw,dcb_[sjs[i1]].zw);count1++;}fclose(fp);}else{printf("回答正确"); }}}if(num==2){printf("请输入背单词的数量"); scanf("%d",&n);for(int i=0;i<n;i++){sjs[i]=rand()%count+1;}for(int i1=0;i1<n;i1++){printf("%s\n",dcb_[sjs[i1]].yw);scanf("%s",zwsr);if(strcmp(zwsr,dcb_[sjs[i1]].zw)!=0){printf("背诵错误,已计入错题本!\n");ctb_[w].c=dcb_[sjs[i1]].j;fp=fopen("D:\\仿真单词本\\dancibencw.txt","a+");if(!fp){printf("打开失败");exit(1); }else {fprintf(fp,"%d %s %s\n",count1+1,dcb_[sjs[i1]].yw,dcb_[sjs[i1]].zw);count1++;}}else{printf("回答正确"); }}}}void lookcw(){typedef struct ct{int c;char Cyw[20];char Czw[20];}ctb;ctb ctb_[1000];int i=0;FILE*fp;fp=fopen("D:\\仿真单词本\\dancibencw.txt","r");if(!fp){printf("打开失败!!!"); exit(1); };fscanf(fp,"%d%s%s",&ctb_[i].c,ctb_[i].Cyw,ctb_[i].Czw);while(!feof(fp)){i++;fscanf(fp,"%d %s %s",&ctb_[i].c,ctb_[i].Cyw,ctb_[i].Czw);}fclose(fp);ctb_[i].c=0;i=0;printf("错题如下\n");while(ctb_[i].c!=0){printf("%d %s %s\n",ctb_[i].c,ctb_[i].Cyw,ctb_[i].Czw);i++;} }void search(){ int i=0;typedef struct stu{int j;char yw[20];char zw[20];}dcb;dcb dcb_[1000];FILE *fp;fp=fopen("D:\\仿真单词本\\dancibenqb.txt","r");if(!fp){printf("打开失败!");exit(1);};fscanf(fp,"%d%s%s",&dcb_[i].j,dcb_[i].yw,dcb_[i].zw);while(!feof(fp)){i++;fscanf(fp,"%d%s%s",&dcb_[i].j,dcb_[i].yw,dcb_[i].zw);}int count=i;int se;int m=0; char srdc[20];printf("请选择:\n1 查英文\n2 查汉语\n") ;scanf("%d",&se);if(se==1){printf("请输入要查询的中文:"); scanf("%s",srdc);while(strcmp(dcb_[m].zw,srdc)!=0&&m<count)m++;if(m<count)printf("\n 该单词中文意思为:%s",dcb_[m].yw);elseprintf("抱歉,未找到该单词");}if(se==2){printf("请输入要查询的英文:");scanf("%s",srdc);while(strcmp(dcb_[m].yw,srdc)!=0&&m<count)m++;if(m<count)printf("\n 该单词意思为:%s",dcb_[m].zw);elseprintf("抱歉,未找到该单词");}}void movecc(){char del[100];typedef struct ct{int c;char Cyw[20];char Czw[20];}ctb;ctb ctb_[1000];int i=0,num;int se=0;FILE*fp,*fp1;fp=fopen("D:\\仿真单词本\\dancibencw.txt","r+");fp1=fopen("D:\\仿真单词本\\dancibencw1.txt","w+");if(!fp){printf("打开失败!!!"); exit(1); };if(!fp1){printf("打开失败!!!"); exit(1); };fscanf(fp,"%d%s%s",&ctb_[i].c,ctb_[i].Cyw,ctb_[i].Czw);while(!feof(fp)){i++;fscanf(fp,"%d%s%s",&ctb_[i].c,ctb_[i].Cyw,ctb_[i].Czw);}fclose(fp);int count=i;printf("请输入要删除的单词");scanf("%s",del);for(i=0;i<count+1;i++){if(!strcmp(del,ctb_[i].Czw)){printf("删除成功");se=i;num=1; break;}if(!strcmp(del,ctb_[i].Cyw)){printf("删除成功");se=i;num=1;break;}if(num==1){ printf("删除失败");return ;} }ctb_[count].c=0;strcpy(ctb_[count+1].Czw,"###");strcpy(ctb_[count+1].Cyw,"###");for(i=se;i<count;i++){ctb_[i]=ctb_[i+1];}int m=0; printf("输出当前错词表\n"); while(ctb_[m].c!=0){fprintf(fp1,"%d %s %s\n",m+1,ctb_[m].Cyw,ctb_[m].Czw);printf("%d %s %s\n",m+1,ctb_[m].Cyw,ctb_[m].Czw);m++;};if(remove("D:\\仿真单词本\\dancibencw.txt")!=0)printf("删除失败!!!"); fclose(fp1);rename("D:\\仿真单词本\\dancibencw1.txt","D:\\仿真单词本\\dancibencw.txt"); }void beidancicw(){typedef struct ct{int c;char Cyw[20];char Czw[20];}ctb;ctb ctb_[1000];FILE *fp;int sjs[50]={0};char sr[20];int q=0,n; fp=fopen("D:\\仿真单词本\\dancibencw.txt","r");fscanf(fp,"%d%s%s",&ctb_[q].c,ctb_[q].Cyw,ctb_[q].Czw);while(!feof(fp)){q++;fscanf(fp,"%d%s%s",&ctb_[q].c,ctb_[q].Cyw,ctb_[q].Czw);}int count1=q;fclose(fp);printf("请输入背单词的数量"); scanf("%d",&n);srand(time(NULL));for(int i=0;i<n;i++){sjs[i]=rand()%count1+1;}for(int i1=0;i1<n;i1++){printf("%s\n",ctb_[sjs[i1]].Czw);scanf("%s",sr);if(strcmp(sr,ctb_[sjs[i1]].Cyw)!=0){printf("背诵错误\n");}else{printf("回答正确\n"); }}}void menu(){printf(" \n\n");printf(" 仿真单词本\n");printf("\t*************************************************************************************************\n");printf("请输入您要选择的内容:\n");printf(" 0:退出程序 \n ");printf("1:查找模式 \n ");printf("2:全文背诵模式 \n ");printf("3:错词背诵模式 \n ");printf("4:查看全部单词 \n ");printf("5:查看全部错词 \n ");printf("6: 移除一个错词 \n");printf("\n");printf("\t**********************************************************************************************\n");int num;scanf("%d",&num);switch(num){case 0:k=0;break;case 1:search();break;case 2:beidanci();break; case 3:beidancicw();break;case 4:words();break;case 5:lookcw();break;case 6:movecc();break;default:printf("请在0--8之间选择");}}