| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
 本帖最后由 孤世星辰 于 2021-5-13 09:18 编辑  
 
 
 
- #include<stdio.h>
 
 - #include<stdlib.h>
 
 - #include<string.h>
 
  
- struct Call
 
 - {
 
 -         char name[20];
 
 -         int phone[20];
 
 -         struct Call *next;
 
 - };
 
  
- void getInput(struct Call *call);
 
 - void addPerson(struct Call **head);
 
 - struct Call *findPerson(struct Call *head);
 
 - void displayContacts(struct Call *head);
 
 - void printPerson(struct Call *call);
 
 - void changePerson(struct Call *head);
 
 - void delPerson(struct Call **head);
 
 - void getInput(struct Call *call)
 
 - {
 
 -         printf("请输入姓名:");
 
 -         scanf("%s",call->name);
 
 -         printf("请输入电话:");
 
 -         scanf("%d",call->phone);
 
 - }
 
 - void addPerson(struct Call **head)
 
 - {
 
 -         struct Call *call,*temp;
 
 -         static struct Call *tail;
 
 -         call=(struct Call *)malloc(sizeof(struct Call));
 
 -         if(call==NULL)
 
 -         {
 
 -                 printf("内存分配失败!\n");
 
 -                 exit(1);
 
 -         }
 
 -         getInput(call);
 
 -         if(*head!=NULL)
 
 -         {
 
 -                 tail->next=call;
 
 -                 call->next=NULL;
 
 -         }
 
 -         else
 
 -         {
 
 -                 *head=call;
 
 -                 call->next=NULL;
 
 -         }
 
 -         tail=call;
 
 - }
 
 - struct Call *findPerson(struct Call *head)
 
 - {
 
 -         struct Call *call;
 
 -         char input[128];
 
 -         call=head;
 
 -         printf("请输入要查找的姓名:");
 
 -         scanf("%s",input);
 
 -         while(call!=NULL)
 
 -         {
 
 -                 if(!strcmp(call->name,input)||call!=NULL)
 
 -                 {
 
 -                         break;
 
 -                 }
 
 -                 call=call->next;
 
 -         }
 
 -         return call;
 
 - }
 
 - void displayContacts(struct Call *head)
 
 - {
 
 -         struct Call *call;
 
 -         int count=1;
 
 -         while(call != NULL)
 
 -         {
 
 -                 printf("第%d位联系人",count);
 
 -                 printf("姓名:%s\n",call->name);
 
 -                 printf("电话:%d\n",call->phone);
 
 -                 call=call->next;
 
 -                 count++;
 
 -         }
 
 - }
 
 - void printPerson(struct Call *call)
 
 - {
 
 -         printf("姓名:%s",call->name);
 
 -         printf("电话:%d",call->phone);
 
 - }
 
 - void changePerson(struct Call *head)
 
 - {
 
 -         struct Call *call;
 
 -         call=findPerson(head);
 
 -         if(call==NULL)
 
 -         {
 
 -                 printf("找不到!\n");
 
 -         }
 
 -         else
 
 -         {
 
 -                 printf("请输入新的号码:");
 
 -                 scanf("%s",call->phone);
 
 -         }
 
 - }
 
 - void delPerson(struct Call **head)
 
 - {
 
 -         struct Call *call;
 
 -         struct Call *temp;
 
 -         struct Call *pre;
 
 -         struct Call *current;
 
 -         call=findPerson(*head);
 
 -         if(call==NULL)
 
 -         {
 
 -                 printf("没找到!\n");
 
 -         }
 
 -         else
 
 -         {
 
 -                 current=*head;
 
 -                 pre=NULL;
 
 -                 while(current!=NULL&¤t!=call)
 
 -                 {
 
 -                         pre=current;
 
 -                         current=current->next;
 
 -                 }
 
 -                 if(pre==NULL)
 
 -                 {
 
 -                         *head=current->next;
 
 -                 }
 
 -                 else
 
 -                 {
 
 -                         pre->next=current->next;
 
 -                 }
 
 -                 free(call);
 
 -         }
 
 - }
 
 - void releaseContacts(struct Call **head)
 
 - {
 
 -         struct Call *temp;
 
 -         while(head!=NULL)
 
 -         {
 
 -                 temp=*head;
 
 -                 *head=(*head)->next;
 
 -                 free(temp);
 
 -         }
 
 - }
 
 - main(void)
 
 - {
 
 -         struct Call *head=NULL;
 
 -         struct Call *call;
 
 -         int input;
 
 -         printf("| 欢迎使用通讯录管理程序 |\n");
 
 -         printf("|--- 1:插入新的联系人--- |\n");
 
 -         printf("|--- 2:查找新的联系人--- |\n");
 
 -         printf("|--- 3:更改新的联系人--- |\n");
 
 -         printf("|--- 4:删除新的联系人--- |\n");
 
 -         printf("|--- 5:显示新的联系人--- |\n");
 
 -         printf("|--- 6:退出新的联系人--- |\n");
 
 -         while(1)
 
 -         {
 
 -                 printf("\n请输入代码指令:");
 
 -                 scanf("%d",&input);
 
 -                 switch(input)
 
 -                 {
 
 -                         case 1:addPerson(&head); break;
 
 -                         case 2:findPerson(head);
 
 -                                 if(call==NULL)
 
 -                                 {
 
 -                                         printf("找不到!\n");
 
 -                                }
 
 -                                 else
 
 -                                 {
 
 -                                         printPerson(call);
 
 -                                 }
 
 -                                 break;
 
 -                         case 3:changePerson(head);break;
 
 -                         case 4:delPerson(&head);break;
 
 -                         case 5:displayContacts(head);break;
 
 -                         case 6:goto END;
 
 -                 }
 
 -         }
 
 - END:
 
 -         releaseContacts(&head);
 
  
-         return 0;
 
 
  复制代码 
你这个代码的问题也太多了吧,有认真检查代码吗 
- #include<stdio.h>
 
 - #include<stdlib.h>
 
 - #include<string.h>
 
  
- struct Call
 
 - {
 
 -     char name[20];
 
 -     int phone[20];
 
 -     struct Call *next;
 
 - };
 
  
- void getInput(struct Call *call);
 
 - void addPerson(struct Call **head);
 
 - struct Call *findPerson(struct Call *head);
 
 - void displayContacts(struct Call *head);
 
 - void printPerson(struct Call *call);
 
 - void changePerson(struct Call *head);
 
 - void delPerson(struct Call **head);
 
 - void getInput(struct Call *call)
 
 - {
 
 -     printf("请输入姓名:");
 
 -     scanf("%s",call->name);
 
 -     printf("请输入电话:");
 
 -     scanf("%d",call->phone);
 
 - }
 
 - void addPerson(struct Call **head)
 
 - {
 
 -     //struct Call *call,*temp;
 
 -     struct Call *call;
 
 -     static struct Call *tail;
 
 -     call=(struct Call *)malloc(sizeof(struct Call));
 
 -     if(call==NULL)
 
 -     {
 
 -         printf("内存分配失败!\n");
 
 -         exit(1);
 
 -     }
 
 -     getInput(call);
 
 -     if(*head!=NULL)
 
 -     {
 
 -         tail->next=call;
 
 -         call->next=NULL;
 
 -     }
 
 -     else
 
 -     {
 
 -         *head=call;
 
 -         call->next=NULL;
 
 -     }
 
 -     tail=call;
 
 - }
 
 - struct Call *findPerson(struct Call *head)
 
 - {
 
 -     struct Call *call;
 
 -     char input[128];
 
 -     call=head;
 
 -     printf("请输入要查找的姓名:");
 
 -     scanf("%s",input);
 
 -     while(call!=NULL)
 
 -     {
 
 -         if(!strcmp(call->name,input)||call!=NULL)
 
 -         {
 
 -             break;
 
 -         }
 
 -         call=call->next;
 
 -     }
 
 -     return call;
 
 - }
 
 - void displayContacts(struct Call *head)
 
 - {
 
 -     //struct Call *call;
 
 -     struct Call *call = head;
 
 -     int count=1;
 
 -     while(call != NULL)
 
 -     {
 
 -         printf("第%d位联系人",count);
 
 -         printf("姓名:%s\n",call->name);
 
 -         //printf("电话:%d\n",call->phone);
 
 -         printf("电话:%d\n", *call->phone);
 
 -         call=call->next;
 
 -         count++;
 
 -     }
 
 - }
 
 - void printPerson(struct Call *call)
 
 - {
 
 -     printf("姓名:%s",call->name);
 
 -     //printf("电话:%d",call->phone);
 
 -     printf("电话:%d", *call->phone);
 
 - }
 
 - void changePerson(struct Call *head)
 
 - {
 
 -     struct Call *call;
 
 -     call=findPerson(head);
 
 -     if(call==NULL)
 
 -     {
 
 -         printf("找不到!\n");
 
 -     }
 
 -     else
 
 -     {
 
 -         printf("请输入新的号码:");
 
 -         //scanf("%s",call->phone);
 
 -         scanf("%d",call->phone);
 
 -     }
 
 - }
 
 - void delPerson(struct Call **head)
 
 - {
 
 -     struct Call *call;
 
 -     //struct Call *temp;
 
 -     struct Call *pre;
 
 -     struct Call *current;
 
 -     call=findPerson(*head);
 
 -     if(call==NULL)
 
 -     {
 
 -         printf("没找到!\n");
 
 -     }
 
 -     else
 
 -     {
 
 -         current=*head;
 
 -         pre=NULL;
 
 -         while(current!=NULL&¤t!=call)
 
 -         {
 
 -             pre=current;
 
 -             current=current->next;
 
 -         }
 
 -         if(pre==NULL)
 
 -         {
 
 -             *head=current->next;
 
 -         }
 
 -         else
 
 -         {
 
 -             pre->next=current->next;
 
 -         }
 
 -         free(call);
 
 -     }
 
 - }
 
 - void releaseContacts(struct Call **head)
 
 - {
 
 -     struct Call *temp;
 
 -     while(head!=NULL)
 
 -     {
 
 -         temp=*head;
 
 -         *head=(*head)->next;
 
 -         free(temp);
 
 -     }
 
 - }
 
 - //main(void)
 
 - int main(void)
 
 - {
 
 -     struct Call *head=NULL;
 
 -     struct Call *call;
 
 -     int input;
 
 -     printf("| 欢迎使用通讯录管理程序 |\n");
 
 -     printf("|--- 1:插入新的联系人--- |\n");
 
 -     printf("|--- 2:查找新的联系人--- |\n");
 
 -     printf("|--- 3:更改新的联系人--- |\n");
 
 -     printf("|--- 4:删除新的联系人--- |\n");
 
 -     printf("|--- 5:显示新的联系人--- |\n");
 
 -     printf("|--- 6:退出新的联系人--- |\n");
 
 -     while(1)
 
 -     {
 
 -         printf("\n请输入代码指令:");
 
 -         scanf("%d",&input);
 
 -         switch(input)
 
 -         {
 
 -             case 1:addPerson(&head); break;
 
 -             //case 2:findPerson(head);
 
 -             case 2: call = findPerson(head);
 
 -                    if(call==NULL)
 
 -                    {
 
 -                        printf("找不到!\n");
 
 -                    }
 
 -                    else
 
 -                    {
 
 -                        printPerson(call);
 
 -                    }
 
 -                    break;
 
 -             case 3:changePerson(head);break;
 
 -             case 4:delPerson(&head);break;
 
 -             case 5:displayContacts(head);break;
 
 -             case 6:goto END;
 
 -         }
 
 -     }
 
 - END:
 
 -     releaseContacts(&head);
 
  
-     return 0;
 
 - }
 
 
  复制代码 
 
 
 |   
 
 
 
 |