通讯录的源代码(用链表实现)

作者:凯旋网络来源:凯旋网络
intf(" please input the sb''s meg:");
      printf(" name:");
 scanf("%s",s->name);
 printf(" Addr:");
 scanf("%s",s->addr);
 printf(" phnum:");
 scanf("%s",s->phnum);
 if(head==NULL)
 head=s;
 else
 r->next=s;
 r=s;
}
;
;
;
void Alter()  /*改变一个人的信息*/
{
 int j;
 printf(" Please input the name:");
     gets(name1); /*输入要人的姓名*/
 p3=head;
 while(strcmp(name1,p3->name)!=0&&p3!=NULL)
 p3=p3->next;
 if(p3==NULL)
 printf(" It is not exit in the addr-book!");
 else
     {  printf(" please input the new meg!"); /*输入要改人的新信息*/
 printf(" name:");  
 scanf("%s",name1);
 strcpy(p3->name,name1);
 printf(" Addr:");
 scanf("%s",name1);
 strcpy(p3->addr,name1);
 printf(" phnum:");
 scanf("%s",name1);
 strcpy(p3->phnum,name1);
      }
}
;
;
;
void Save()  /*保存信息*/
{ int j;
 fp=fopen("people.txt","w");
 for(p2=head,j=0;p2!=NULL;j++,p2=p2->next)/*将信息装出入结构体数组在出入链表中*/
 {          /*避免地址的出入,造成乱码文件*/
 strcpy(persons[j].name,p2->name);
 strcpy(persons[j].addr,p2->addr);
 strcpy(persons[j].phnum,p2->phnum);
 fwrite(&persons[j],sizeof(struct persons),1,fp);
 }
}
;
;
;
void main()
{ creat();
 do
    {  printf(" WELCOME TO USE Pan Weifeng''s Address book");/*显示提示的信息*/
 printf(" Please make a choice below:");
 printf(" 1.Show all the meg");
 printf(" 2.Delete a piece of meg");
 printf(" 3.Find a piece of meg");
 printf(" 4.Insert a piece of meg");
 printf(" 5.Alter a piece of meg");
 printf(" 6.Save and Exit");
 printf(" ");
 printf(" Input Your Choice:");
 ch=getche();
 switch(ch)
       {   case ''1'':  Show(); /*用单条件多选择语句实现调用与循环*/
        break;
           case ''2'':  Delete();
        break;
           case ''3'':  Find();
        break;

    case ''4'':  Input();
        break;
    case ''5'':  Alter();
        break;
    case ''6'':  Save();
        fclose(fp);
        exit(0);
        break;
    default:
     printf(" ********************************* ");
     printf("      The num should 1-4!!! 
  • 广告推荐