diff --git a/通讯录.c b/通讯录.c index 14fa9ac..5502e72 100644 --- a/通讯录.c +++ b/通讯录.c @@ -80,13 +80,91 @@ void add() //ÐÞ¸Ä void modify() { - + char namekey[8]; + printf("ÊäÈëÒª²éѯµÄÐÕÃû£º"); + scanf("%s",namekey); + if((fp=fopen("user.txt","ab+"))==NULL) //´ò¿ªÎļþ + { + printf("\n²»ÄÜ´ò¿ªÎļþ£¡\n"); + exit(0); + } + int m=0,t=1; + while(!feof(fp)) + { + fread(&user[m],sizeof(struct user),1,fp)==1; //¶ÁÈ¡½á¹¹ÌåÖÐÒ»¸öÓû§ÐÅÏ¢ + if(!strcmp(user[m].name,namekey)) //ÅжÏÊÇ·ñÏàͬ + { + t=0; //ÈôÏàͬ£¬ÔòÔÚºóÃæif¾äÖÐÊä³ö + break; + } + m++; + } + if(t) + printf("δÕÒµ½\n"),fclose(fp),system("pause"),menu(); + else + { + printf("ÕÒµ½\n"); + printf("ÐÕÃû\t\t¼®¹á\t\tµç»°1\t\tµç»°2\t\tÓÊÏä\n"); + printf("%-8s\t",user[m].name); + printf("%-15s\t",user[m].place); + printf("%-15s\t",user[m].tel1); + printf("%-15s\t",user[m].tel2); + printf("%-20s\t",user[m].email); + } + printf("\nÄúÏëÒªÐÞ¸ÄÄÄÌõÐÅÏ¢£¿\n\n1.ÐÕÃû\t2.¼®¹á\t3.µç»°1\t4.µç»°2\t5.ÓÊÏä\tÆäËüÈÎÒâ¼ü.²»ÐÞ¸Ä"); //ÐÞ¸ÄÐÅÏ¢Ìáʾ + int a; //Ð޸ĵÄÐÅÏ¢ÐòºÅ + scanf("%d",&a); + char *newname; + char nweplace[15]; + char newtel1[15]; + char newtel2[15]; + char newemail[20]; + switch(a) + { + case 1:scanf("%s",newname),strcpy(user[m].name,newname),printf("%s",user[m].name);break; + default:break; + } + printf("Ð޸ijɹ¦\n"); + fclose(fp); + system("pause"); menu(); } //²éѯ void search() { - + char namekey[8]; + printf("ÊäÈëÒª²éѯµÄÐÕÃû£º"); + scanf("%s",namekey); + if((fp=fopen("user.txt","r"))==NULL) //´ò¿ªÎļþ + { + printf("\n²»ÄÜ´ò¿ªÎļþ£¡\n"); + exit(0); + } + int m=0,t=0; + while(!feof(fp)) + { + fread(&user[m],sizeof(struct user),1,fp)==1; //¶ÁÈ¡½á¹¹ÌåÖÐÒ»¸öÓû§ÐÅÏ¢ + if(!strcmp(user[m].name,namekey)) //ÅжÏÊÇ·ñÏàͬ + { + t=1; //ÈôÏàͬ£¬ÔòÔÚºóÃæif¾äÖÐÊä³ö + break; + } + m++; + } + if(t) + { + printf("ÕÒµ½\n"); + printf("ÐÕÃû\t\t¼®¹á\t\tµç»°1\t\tµç»°2\t\tÓÊÏä\n"); + printf("%-8s\t",user[m].name); + printf("%-15s\t",user[m].place); + printf("%-15s\t",user[m].tel1); + printf("%-15s\t",user[m].tel2); + printf("%-20s\t",user[m].email); + } + else + printf("δÕÒµ½\n"); + fclose(fp); + system("pause"); menu(); } //ä¯ÀÀ diff --git a/通讯录.exe b/通讯录.exe index 101de30..00eb821 100644 Binary files a/通讯录.exe and b/通讯录.exe differ