⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.txt

📁 通讯录的源代码用链表实现 通讯录的源代码用链表实现 还不错
💻 TXT
字号:
/*通讯录的源代码(用链表实现)*/   
    
  #include   <stdio.h>   
  #include   <stdlib.h>
  #include   <string.h>   
  #define   maxlen   100   
  struct   persons   
  {   char   name[10];
    char   addr[20];   
    char   phnum[10];   
    }persons[maxlen];   

  typedef   struct   lnode{
    char   name[10];
    char   addr[20];
    char   phnum[10];
    struct   lnode   *next;   
    }listnode,*linklist;   
    
    linklist   head=NULL,r=NULL;
    listnode     *s,*p0,*p1,*p2,*p3,*p4,*p5,*p6,*p7;   
    int   i;   
    char   name1[10],ch;   
    char   str1[20];   
    FILE   *fp;
    
  void   creat()
  {       int   j;   
    long   k;   
    fp=fopen("people.txt","r+t");
    if(fp!=NULL)   
    {for(i=1;i<maxlen;i++)   
  {   j=fgetc(fp);   
    if(j==EOF)   
    return;   
    k=i-1;   
    fseek(fp,k*sizeof(struct   persons),0);
    fread(&persons[i],sizeof(struct   persons),1,fp);   
    s=(linklist)malloc(sizeof(listnode));
    strcpy(s->name,persons[i].name);   
    strcpy(s->addr,persons[i].addr);   
    strcpy(s->phnum,persons[i].phnum);   
    if(head==NULL)
    head=s;   
    else   
    r->next=s;   
    r=s;}   
  }   
    else   
    {   fp=fopen("people.txt","w");
    i=1;   
            }   
  }   
    
  void   Show()
  {         p1=head;   
            while(p1!=NULL)   
        {   printf("\n\n\tname:%s\n",p1->name);   
            printf("\n\n\taddr:%s",p1->addr);   
            printf("\n\n\tphnum:%s",p1->phnum);   
            p1=p1->next;   
          }   
    }   
    
  void   Delete()
  {   printf("\n\n\tplease   input   the   name:");   
    gets(name1);
    p4=head;   
    if(strcmp(p4->name,name1)==0)   
            {     p4=p4->next;
    head=p4;   
            }   
    else   
            {     while(strcmp(p4->next->name,name1)!=0)   
    p4=p4->next;   
    p5=p4->next;   
    p4->next=p5->next;   
    /8   
    }   
    
    }   
    
  void   Find()
  {       printf("\n\n\tplease   input   the   name:");   
      p0=head;   
      gets(name1);
          while(strcmp(name1,p0->name)!=0&&p0!=NULL)   
      p0=p0->next;   
      if(p0==NULL)   
      printf("\n\n\tIt   is   not   exit   in   the   addr-book!");   
      else   
              {     printf("\n\n\tname:%s\n",p0->name);   
      printf("\n\n\taddr:%s",p0->addr);   
      printf("\n\n\tphnum:%s",p0->phnum);   
                  }   
  }   
    
  void   Input()
  {   s=(linklist)malloc(sizeof(listnode));   
            printf("\n\n\tplease input the sombody's message:");   
              printf("\n\n\t\tname:");   
    scanf("%s",s->name);   
    printf("\n\n\t\tAddr:");   
    scanf("%s",s->addr);   
    printf("\n\n\t\tphnum:");   
    scanf("%s",s->phnum);   
    if(head==NULL)   
    head=s;   
    else   
    r->next=s;   
    r=s;   
  }   
    
  void   Alter()
  {   
    int   j;   
    printf("\n\n\tPlease input the name:");   
            gets(name1);
    p3=head;   
    while(strcmp(name1,p3->name)!=0&&p3!=NULL)   
    p3=p3->next;   
    if(p3==NULL)   
    printf("\n\n\tIt   is   not   exit   in   the   addr-book!");   
    else   
            {     printf("\n\n\tplease input the new meg!");
    printf("\n\n\t\tname:");       
    scanf("%s",name1);   
    strcpy(p3->name,name1);   
    printf("\n\n\t\tAddr:");   
    scanf("%s",name1);   
    strcpy(p3->addr,name1);   
    printf("\n\n\t\tphnum:");   
    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("\n\n\n\n\twelcome to use vincent address book");
    printf("\n\n\t\tPlease make a choice below:");   
    printf("\n\t\t1.Show all the message");   
    printf("\n\t\t2.Delete a piece of message");   
    printf("\n\t\t3.Find a piece of message");   
    printf("\n\t\t4.Insert a piece of message");   
    printf("\n\t\t5.Alter a piece of message");   
    printf("\n\t\t6.Save and Exit");   
    printf("\n\n\n");   
    printf("\tInput 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("\n\t*********************************\n");   
            printf("\n\t   The   num   should   1-4!!! \n");   
            printf("\n\t**********************************");   
            break;   
    }   
            }while(1);     
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -