diff --git a/增添.c b/增添.c new file mode 100644 index 0000000..dc711d6 --- /dev/null +++ b/增添.c @@ -0,0 +1,265 @@ +#include +#include +#include +#include +#define LEN sizeof(struct info) +struct info +{ + char word[40]; + char mean[40]; +}; +struct info inf[400]; +int m=0; +void enter(); +void add(); +void Delete(); +void Edit(); +void enter() +{ + int i,m=0; + char n; + char to[40]; + printf("ÇëÊäÈëµ¥´Ê: "); + scanf("%s",to); + FILE *fp; + if((fp=fopen("data.txt","ab+"))==NULL) + { + printf("Îļþ²»´æÔÚ!\n"); + exit(1); + } + while(!feof(fp)) + { + if(fread(&inf[m],LEN,1,fp)==1) + { + if(strcmp(to,inf[m].word)==0) + { + printf("%s ",to); + printf("%s\n",inf[m].mean); + printf("ÊÇ·ñ¼ÌÐø?"); + printf("°´Y»òy±íʾ¼ÌÐø,°´ÆäËü¼ü·µ»Ø\n"); + fclose(fp); + return; + } + } + m++; + } + printf("Î޴˵¥´Ê!\n"); + printf("ÊÇ·ñ¼ÌÐø?"); + printf("°´Y»òy±íʾ¼ÌÐø,°´ÆäËü¼ü·µ»Ø\n"); + fclose(fp); + return; + if(m==0) + printf("ÎļþÖÐÎ޼Ǽ!\n"); + if((fp=fopen("data.txt","ab+"))==NULL) + { + printf("Îļþ²»´æÔÚ!\n"); + return; + } + fclose(fp); +} +/*void add() +{ + int i; + char n[20]; + FILE *fp; + if((fp=fopen("data.txt","ab+"))==NULL) + { + printf("Îļþ²»´æÔÚ!\n"); + exit(0); + } + printf("ÇëÊäÈëµ¥´Ê: \n"); + scanf("%s",n); + while(!feof(fp)) + { + if(fread(&inf[m],LEN,1,fp)==1) + { + if(strcmp(n,inf[m].word)==0) + { + printf("ÒÑÓд˵¥´Ê£¬ÊÇ·ñ½øÐÐÐÞ¸Ä?\n"); + printf("1. ÊÇ 2. ·ñ\n"); + scanf("%d",&i); + switch(i) + { + case 1: + Edit(); + case 2: + break; + } + printf("ÊÇ·ñ¼ÌÐøÔöÌí?"); + printf("°´Y»òy±íʾ¼ÌÐø,°´ÆäËü¼ü·µ»Ø\n"); + fclose(fp); + return; + } + } + m++; + } + printf("ÇëÊäÈëÊÍÒ壺\n"); + scanf("%s",inf[m].mean); + strcpy(inf[m].word,n); + if(fwrite(&inf[m],LEN,1,fp)!=1) + { + printf("²»Äܱ£´æ"); + } + else + { + printf("Òѱ£´æ\nÊÇ·ñ¼ÌÐøÌí¼Ó£¿"); + printf("°´Y»òy±íʾ¼ÌÐø,°´ÆäËü¼ü·µ»Ø\n"); + } + fclose(fp); +} +void Delete() +{ + FILE *fp,*ft; + char n[40],k[40]; + int m=0,l=0,i; + printf("ÇëÊäÈëҪɾ³ýµÄµ¥´Ê£º\n"); + scanf("%s",n); + fp=fopen("data.txt","rb+"); + ft=fopen("123.txt","wb+"); + if(fp==NULL||ft==NULL) + { + printf("Îļþ²»´æÔÚ!\n"); + exit(1); + } + printf("ÊÇ·ñɾ³ý´Ëµ¥´Ê£¿½÷É÷¿¼ÂÇ£¡\n"); + printf("\t1.ÊÇ"); + printf("\t\t2.·ñ\n"); + scanf("%d",&i); + switch(i) + { + case 1: + while(fread(k,sizeof(k),1,fp)) + { + if(strcmp(k,n)!=0) + { + fwrite(k,sizeof(k),1,ft); + m++; + } + else + { + rewind(fp); + fseek(fp,sizeof(k)*(m+2),0); + } + } + fclose(fp); + fclose(ft); + remove("data.txt"); + rename("123.txt","data.txt"); + printf("ɾ³ý³É¹¦"); + break; + case 2:break; + } + printf("ÊÇ·ñ¼ÌÐø?\n"); + printf("°´Y»òy±íʾ¼ÌÐø,°´ÆäËü¼ü·µ»Ø\n"); + return; +} +void Edit() +{ + int t,a,m=0; + char n[40],k[40]; + FILE *fp; + printf("ÇëÊäÈëÒªÐ޸ĵĵ¥´Ê£º"); + scanf("%s",n); + if((fp=fopen("data.txt","rb+"))==NULL) + { + printf("Îļþ²»´æÔÚ!\n"); + exit(1); + } + rewind(fp); + while(!feof(fp)) + { + if(fread(&inf[m],LEN,1,fp)==1) + if(strcmp(n,inf[m].word)==0) + { + printf("ÊÇ·ñÐÞ¸ÄÊÍÒ壿\n"); + printf("\t1.ÊÇ."); + printf("\t\t2.·ñ.\n"); + scanf("%d",&a); + switch(a) + { + case 1:printf("ÇëÊäÈëÐ޸ĺóµÄÊÍÒ壺"); + scanf("%s",k); + strcpy(inf[m].mean,k); + t=sizeof(inf[m].mean); + fseek(fp,-t,1); + if(fwrite(&inf[m].mean,t,1,fp)==1) + printf("Ð޸ijɹ¦!"); + break; + case 2: + break; + } + printf("ÊÇ·ñ¼ÌÐø?\n"); + printf("°´Y»òy±íʾ¼ÌÐø,°´ÆäËü¼ü·µ»Ø\n"); + fclose(fp); + return; + } + m++; + } + printf("Î޴˵¥´Ê\n"); + printf("ÊÇ·ñ¼ÌÐøÐÞ¸Ä?\n"); + printf("ÊäÈëy»òY¼ÌÐø²Ù×÷£¬ÊäÈëÆäËû·µ»Ø²Ëµ¥\n"); + fclose(fp); + return; +}*/ +int main(void) +{ +int choice; +char n[2]; +do +{ +printf("\n\t =============================="); +printf("\n\t *»¶Ó­Ê¹ÓÃÓÐÏÞ¹æÄ£µç×ÓÓ¢ºº´Êµä*"); +printf("\n\t ==============================\n"); +printf("\n\t ***********²Ëµ¥ÏÔʾ***********\n"); +printf("\n\t ********¡¾1¡¿´ÊÌõ²éÕÒ*********\n"); +printf("\n\t ********¡¾2¡¿´ÊÌõÔö´Ê*********\n"); +printf("\n\t ********¡¾3¡¿´ÊÌõɾ³ý*********\n"); +printf("\n\t ********¡¾4¡¿´ÊÌõÐÞ¸Ä*********\n"); +printf("\n\t ********¡¾0¡¿Í˳ö´Êµä*********\n"); +printf("ÇëÑ¡ÔñÄãÒª½øÐеŦÄÜ£º"); +scanf("%d",&choice); +switch(choice) +{ + case 1: + enter(); + scanf("%s",&n); + while(n[0]=='Y'||n[0]=='y') + { + enter(); + scanf("%s",&n); + } + break; + case 2: +/* add(); + m++; + scanf("%s",&n); + while(n[0]=='Y'||n[0]=='y') + { + add(); + m++; + scanf("%s",&n); + }*/ + break; + case 3: +/* Delete(); + scanf("%s",&n); + while(n[0]=='Y'||n[0]=='y') + { + Delete(); + scanf("%s",&n); + } */ + break; + case 4: +/* Edit(); + scanf("%s",&n); + while(n[0]=='Y'||n[0]=='y') + { + Edit(); + scanf("%s",&n); + } */ + break; + } +}while(choice!=0); +return 0; +} + diff --git a/增添.exe b/增添.exe new file mode 100644 index 0000000..e6f2e06 Binary files /dev/null and b/增添.exe differ