del.c

来自「大一时课程设计 通信录管理系统 可作为C课程设计的参考」· C语言 代码 · 共 62 行

C
62
字号
#include"yy.h"

NODE *del_by_name(NODE *head)
{
    NODE *p0,*p1,*p2;
    char name[16];
    if(head==NULL){printf("\n\tlist null!\n");
                   goto end;}
    p0=p1=head;
    printf("please input the name  and the adress will be del!!!\n\t");
    gets(name);
    while(strcmp(name,p1->name)!=0&&p1->next!=NULL)
        {p2=p1;
         p1=p1->next;
         }
    if(strcmp(name,p1->name)==0)
       {if(p1==head)head=p1->next;
        else{p0=p1;p2->next=p1->next;}

        printf("\nThe del address is:\n");
        printf("Name              Phone              Sex      Age      Birthday      Dormitory\n");
        printf("%-18s%-19s%-9c%-9d%-14s%s\n",p0->name,p0->phone,p0->sex,
                p0->age,p0->birthday,p0->dormitory);

        free(p0);
        n-=1;
        }
    else printf("%s not been found!\n",name);
    end:
    return head;
}

NODE *del_by_phone(NODE *head)
{
    NODE *p0,*p1,*p2;
    char phone[18];
    if(head==NULL){printf("\n\tlist null!\n");
           goto end2;}
    p0=p1=head;
    printf("please input the phone and the adress will be del!!!\n\t");
    gets(phone);
    while(strcmp(phone,p1->phone)!=0&&p1->next!=NULL)
        {p2=p1;
         p1=p1->next;
         }
    if(strcmp(phone,p1->phone)==0)
       {if(p1==head)head=p1->next;
        else{p0=p1;p2->next=p1->next;}

        printf("\nThe del address is:\n");
        printf("Name              Phone              Sex      Age      Birthday      Dormitory\n");
        printf("%-18s%-19s%-9c%-9d%-14s%s\n",p0->name,p0->phone,p0->sex,
                p0->age,p0->birthday,p0->dormitory);

        free(p0);
        n-=1;
        }
    else printf("%s not been found!\n",phone);
    end2:
    return head;
}

⌨️ 快捷键说明

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