From 59724693a26c89a28744baeb79d210a4e2d03e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E6=99=B6=E6=99=B6?= <447539854@qq.comomm> Date: Fri, 11 Jan 2019 19:51:39 +0800 Subject: [PATCH] first commit --- c1.1.cpp | 422 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 422 insertions(+) create mode 100644 c1.1.cpp diff --git a/c1.1.cpp b/c1.1.cpp new file mode 100644 index 0000000..ee59459 --- /dev/null +++ b/c1.1.cpp @@ -0,0 +1,422 @@ +#include +#include +#include +#include +#include + +void add(); +void finds(); +void clean(); +void menus(); +void delet(); +void modify(); + +FILE *fp; + +int num=0; + +struct word +{ + char en[100]; + char ch[100]; + char ex[100]; + +}s[200]; + +//清屏 +void clean() +{ + int choice; + system("cls"); + printf("\n") ; + menus(); + scanf("%d",&choice); + printf("\n") ; + switch(choice) + { + case 1: + add();break; + case 2: + finds();break; + case 3: + clean();break; + case 4: + delet();break; + case 5: + modify();break; + case 0: + break; + + } +} + +//创建文件并打开文件 +void add() +{ + + int a,b,c,choice; + char next='1'; + char word[100]; + FILE *fp; + if((fp=fopen("f4.txt","a+"))==NULL)//创建并打开文件,和防止文件打开失败。 + { + printf("cann't open file"); + exit(0); + } + fseek(fp,0,SEEK_END);//定位到文件末尾 + while(next=='1') + { + printf("\n请输入单词的英文:"); + scanf("%s",s[num].en); + a=fprintf(fp,"%s\t",s[num].en); + + printf("\n请输入单词的释义:"); + scanf("%s",s[num].ch); + b=fprintf(fp,"%s\t",s[num].ch); + + printf("\n请输入单词的例句:"); + scanf("%s",s[num].ex); + c=fprintf(fp,"%s\t",s[num].ex); + + + if(a&&b&&c) + { + printf("\n输入成功\n"); + num++; + printf("%d",num); + } + else + printf("\n输入失败\n"); + printf("\nWould you like to enter more items(Yes--1/No--除1以外的任意键)\n"); + printf("\n返回主菜单按'#'号键") ; + fflush(stdin);//清空输入缓冲区 + next=getch(); + } + if(next=='#') + { + printf("\n") ; + menus(); + scanf("%d",&choice); + printf("\n") ; + switch(choice) + { + case 1: + add();break; + case 2: + finds();break; + case 3: + clean();break; + case 4: + delet();break; + case 5: + modify();break; + case 0: + break; + + } + } + + if(fclose(fp))//关闭文件并防止文件关闭失败。 + { + printf("cann't close file"); + exit(0); + } +} + +//查找单词 +void finds() +{ + rewind(fp); + int i,choice,flag=0; + char find='2'; + char n; + char w[100]; + if((fp=fopen("f4.txt","r"))==NULL)//打开文件,和防止文件打开失败。 + { + printf("cann't open file"); + exit(0); + } + + while(find=='2') + { + printf("\n请输入需要查找的单词:"); + scanf("%s",w); + for(i=0;i<=10;i++)//先找到该中文形式对应的序号 + { + fscanf(fp,"%s\t%s\t%s\t",s[i].en,s[i].ch,s[i].ex); + if(strcmp(s[i].en,w)==0) + { + printf("\n英文形式 中文形式 例句 "); + printf("\n %-12s%8s%12s",s[i].en,s[i].ch,s[i].ex); + find=1;//退出程序 + } + else + { + char *res = strstr(s[i].en,w); + if(res != NULL) + { + printf("\n你要查询的可能是:"); + printf("%s\n", res); + find=2; + } + } + } + printf("\nWould you like to enter more items(Yes--2/No--除2以外的任意键)\n"); + printf("\n返回主菜单按'#'号键") ; + fflush(stdin);//清空输入缓冲区 + find=getch(); + } + if(find=='#') + { + printf("\n") ; + menus(); + scanf("%d",&choice); + printf("\n") ; + switch(choice) + { + case 1: + add();break; + case 2: + finds();break; + case 3: + clean();break; + case 4: + delet();break; + case 5: + modify();break; + case 0: + break; + + } + } + if(fclose(fp))//关闭文 件并防止文件关闭失败。 + { + printf("cann't close file"); + exit(0); + } +} + +//删除单词信息 +void delet() +{ + int choice ; + FILE *fp; + FILE *fp1; + char set[20]; + int j,d,h,g,u=0; + int sum=0; + char delets='4'; + if((fp=fopen("f4.txt","a+"))==NULL)//创建并打开文件,和防止文件打开失败。 + { + printf("cann't open f4 file"); + exit(0); + } + if((fp1=fopen("linshi.txt","a+"))==NULL)//创建并打开文件,和防止文件打开失败。 + { + printf("cann't open linshi file"); + exit(0); + } + while(delets=='4') + { + printf("\n请输入要删除的单词:\n"); + scanf("%s",set); + for(j=0;j<=10;j++)//先找到该单词形式对应的序号 + { + fscanf(fp,"%s\t%s\t%s\t",s[j].en,s[j].ch,s[j].ex); + if(strcmp(s[j].en,set)!=0) + { + fprintf(fp1,"%s\t",s[j].en); + d=sizeof(s[j].en); + fprintf(fp1,"%s\t",s[j].ch); + h=sizeof(s[j].ch); + fprintf(fp1,"%s\t",s[j].ex); + g=sizeof(s[j].ex); + u=d+g+h; + sum=sum+u; + } + else + { + rewind(fp); + fseek(fp,sum,0); + } + } + if(fclose(fp))//关闭文件并防止文件关闭失败。 + { + printf("cann't close f4 file"); + exit(0); + } + if(fclose(fp1))//关闭文件并防止文件关闭失败。 + { + printf("cann't close linshi file"); + exit(0); + } + remove("f4.txt"); + rename("linshi.txt","f4.txt"); + printf("\n删除成功\n"); + printf("\n继续删除按‘4’,返回菜单按‘#’,退出按任意键\n\n"); + delets=getch(); + } + if(delets=='#') + { + printf("\n") ; + menus(); + scanf("%d",&choice); + printf("\n") ; + switch(choice) + { + case 1: + add();break; + case 2: + finds();break; + case 3: + clean();break; + case 4: + delet();break; + case 5: + modify();break; + case 0: + break; + + } + } +} + +//修改单词信息 +void modify() +{ + int choice; + int i=0,g=1;//chooses代表选项标识,g代表是否找到单词 + int k,h,j; + char choose='5'; + int size_y,size_z,size_l; + int len_y,len_z,len_l; + char x[100]; //查找错误单词 + char y[100]; //正确英文形式 + char z[100]; //正确中文形式 + char l[100]; //正确例句 + + while(choose=='5') + { + if((fp=fopen("f4.txt","r+"))==NULL)//创建并打开文件,和防止文件打开失败。 + { + printf("cann't open file"); + exit(0); + } + + printf("\n请输入你要修改的单词英文形式:"); + scanf("%s",x); + + for(i=0;i<10;i++)//先找到该英文形式对应的序号 + { + fscanf(fp,"%s\t%s\t%s\t",s[i].en,s[i].ch,s[i].ex); + if(strcmp(s[i].en,x)==0) + { + + printf("\n请输入单词正确的英文形式:"); + scanf("%s",y); + + size_y=sizeof(s[i].en); + //len_y=strlen(y); + fseek(fp, 0, SEEK_SET); //指针回滚 + k=fprintf(fp,"%s\t",y); + + printf("\n请输入此单词正确的中文形式:"); + scanf("%s",z); + size_z=strlen(s[i].ch); + //len_z=strlen(z); + h=fprintf(fp,"%s\t",z); + + printf("\n请输入此单词正确的例句:"); + scanf("%s",l); + size_l=strlen(s[i].ex); + //len_l=strlen(l); + j=fprintf(fp,"%s\t",l); + + if(j&&h&&k) + printf("\n修改成功!\n"); + else + { + printf("\n修改不成功!\n"); + printf("没有这个单词!\n"); + } + } + } + printf("\n继续修改请选‘5 ’,返回菜单请选‘# ’:"); + scanf("%d",&choose); + if(fclose(fp))//关闭文件并防止文件关闭失败。 + { + printf("cann't close file"); + exit(0); + } + } + if(choose=='5') + { + printf("\n") ; + menus(); + scanf("%d",&choice); + printf("\n") ; + switch(choice) + { + case 1: + add();break; + case 2: + finds();break; + case 3: + clean();break; + case 4: + delet();break; + case 5: + modify();break; + case 0: + break; + + } + } +} + +//系统菜单 +void menus() +{ + printf("\n"); + printf(" *********************************************************\n"); + printf(" # #\n"); + printf(" # 请选择系统功能选项 #\n"); + printf(" # #\n"); + printf(" *********************************************************\n"); + printf(" # #\n"); + printf(" # 0.退出 1.输入单词 #\n"); + printf(" # #\n"); + printf(" # 2.查找单词 3.清屏 #\n"); + printf(" # #\n"); + printf(" # 4.删除单词 5.修改单词 #\n"); + printf(" # #\n"); + printf(" *********************************************************\n"); + printf("\n"); +} + +int main() +{ + int choice; + printf("\n") ; + menus(); + scanf("%d",&choice); + printf("\n") ; + switch(choice) + { + case 1: + add();break; + case 2: + finds();break; + case 3: + clean();break; + case 4: + delet();break; + case 5: + modify();break; + case 0: + break; + + } + return 0; +} +