• 通讯录程序(未运行成功)


      1 #include<stdio.h>
      2 #include<string.h>
      3 #include<stdlib.h>
      4 
      5 typedef struct{
      6     char num[5];
      7     char name[9];
      8     char sex[3];
      9     char phone[13];
     10     char addr[31];
     11 }DataType;
     12 
     13 typedef struct node{
     14     DataType data;
     15     struct node*next;
     16 }ListNode;
     17 
     18 typedef ListNode*LinkList;
     19 ListNode*p;
     20 LinkList head;
     21 
     22 int menu_select();
     23 LinkList CreateList(void);
     24 void InsertNode(LinkList head, ListNode*p);
     25 ListNode *LinkFind(LinkList head);
     26 void DelNode(LinkList head);
     27 void PrintList(LinkList head);
     28 
     29 void main()
     30 {
     31     for (;;){
     32         switch (menu_select())
     33         {
     34         case 1:
     35             printf("通讯录的建立
    ");
     36             head = CreateList();
     37             break;
     38         case 2:
     39             printf("通讯录结点的插入
    ");
     40             p = (ListNode*) malloc(sizeof(ListNode));
     41             scanf("%s%s%s%s%s", p->data.num, p->data.name, p->data.sex, p->data.phone, p->data.addr);
     42             InsertNode(head, p);
     43             break;
     44         case 3:
     45             printf("通讯录结点的查询
    ");
     46             p = LinkFind(head);
     47             if (p != NULL)
     48             {
     49                 printf("编号 姓名 性别 联系电话 地址
    ");
     50                 printf("%s%s%s%s%s", p->data.num, p->data.name, p->data.sex, p->data.phone, p->data.addr);
     51             }
     52             else
     53                 printf("没查到要查询的通讯者!
    ");
     54             break;
     55         case 4:
     56             printf("通讯录结点的删除
    ");
     57             DelNode(head);
     58             break;
     59         case 5:
     60             printf("通讯录链表的输出
    ");
     61             PrintList(head);
     62             break;
     63         case 0:
     64             printf("再见!
    ");
     65             return;
     66         }
     67     }
     68 }
     69 
     70 int menu_select()
     71 {
     72     int sn;
     73     printf("   通讯录管理系统
    ");
     74     printf("==================
    ");
     75     printf("  1,通讯录的建立
    ");
     76     printf("  2,通讯录结点的插入
    ");
     77     printf("  3,通讯录结点的查询
    ");
     78     printf("  4,通讯录结点的删除
    ");
     79     printf("  5,通讯录链表的输出
    ");
     80     printf("  0,退出管理系统
    ");
     81     printf("==================
    ");
     82     printf("请选择0---5
    ");
     83     for (;;)
     84     {
     85         scanf("%d", &sn);
     86         if (sn < 0 || sn>5)
     87             printf("
    	输入错误。重选0--5");
     88         else
     89             break;
     90     }
     91     return sn;
     92 }
     93 
     94 LinkList CreateList(void)
     95 {
     96     LinkList head = (ListNode*) malloc(sizeof(ListNode));
     97     ListNode *p, *rear;
     98     int flag = 0;
     99     rear = head;
    100     while (flag == 0)
    101     {
    102         p = (ListNode*) malloc(sizeof(ListNode));
    103         printf("编号(4),姓名(8),性别,电话(11),地址(31)
    ");
    104         scanf("%s%s%s%s%s", p->data.num, p->data.name, p->data.sex, p->data.phone, p->data.addr);
    105         rear->next = p;
    106         rear = p;
    107         printf("继续输入吗?(1/0):");
    108         getchar();
    109         scanf("%d", &flag);
    110     }
    111     rear->next = NULL;
    112     return head;
    113 }
    114 
    115 void InsertNode(LinkList head, ListNode*p)
    116 {
    117     ListNode*p1, *p2;
    118     p1 = head;
    119     p2 = p1->next;
    120     while (p2 != NULL && strcmp(p2->data.num, p->data.num) < 0)
    121     {
    122         p1 = p2;
    123         p2 = p2->next;
    124     }
    125     p1->next = p;
    126     p->next = p2;
    127 }
    128 
    129 ListNode *LinkFind(LinkList head)
    130 {
    131     ListNode*p;
    132     char num[5];
    133     char name[9];
    134     int xz;
    135     printf("===========
    ");
    136     printf("1,按编号查询
    ");
    137     printf("2,按姓名查询
    ");
    138     printf("===========
    ");
    139     printf("请选择:");
    140     p = head->next;
    141     scanf("%d", &xz);
    142     if (xz == 1)
    143     {
    144         printf("请输入查找者的编号:");
    145         scanf("%s", num);
    146         while (p && strcmp(p->data.num, num) < 0)
    147             p = p->next;
    148         if (p == NULL && strcmp(p->data.num, num) > 0)
    149             p = NULL;
    150     }
    151     else
    152         if (xz == 2){
    153             printf("请输入要查找者的姓名:
    ");
    154             scanf("%s", name);
    155             while (p && strcmp(p->data.name, name) != 0);
    156             p = p->next;
    157         }
    158         return p;
    159 }
    160 
    161 void DelNode(LinkList head)
    162 {
    163     char jx;
    164     ListNode *p, *q;
    165     p = LinkFind(head);
    166     if (p == NULL){
    167         printf("没有查到想要删除的通讯者
    ");
    168         return;
    169     }
    170     printf("真的要删除该结点吗?(y/n):");
    171     scanf("%c", &jx);
    172     if (jx == 'y' || jx == 'Y')
    173     {
    174         q = head;
    175         while (q != NULL && q->next != p)
    176             q = q->next;
    177         q->next = p->next;
    178         free(p);
    179         printf("通讯者已被删除
    ");
    180     }
    181 }
    182 
    183 void PrintList(LinkList head)
    184 {
    185     ListNode*p;
    186     p = head->next;
    187     printf("编号  姓名 性别 联系电话 地址
    ");
    188     printf("-----------------------------
    ");
    189     while (p != NULL)
    190     {
    191         printf("%s,%s,%s,%s,%s
    ", p->data.num, p->data.name, p->data.sex, p->data.phone, p->data.addr);
    192         printf("-------------------------
    ");
    193         p = p->next;
    194     }
    195 }
      1 #include<stdio.h>
      2 #include<string.h>
      3 #include<stdlib.h>
      4 
      5 typedef struct{
      6     char num[5];
      7     char name[9];
      8     char sex[3];
      9     char phone[13];
     10     char addr[31];
     11 }DataType;
     12 
     13 typedef struct node{
     14     DataType data;
     15     struct node*next;
     16 }ListNode;
     17 
     18 typedef ListNode*LinkList;
     19 ListNode*p;
     20 LinkList head;
     21 
     22 int menu_select();
     23 LinkList CreateList(void);
     24 void InsertNode(LinkList head, ListNode*p);
     25 ListNode *LinkFind(LinkList head);
     26 void DelNode(LinkList head);
     27 void PrintList(LinkList head);
     28 
     29 void main()
     30 {
     31     while(1) {
     32 
     33     switch (menu_select())
     34         {
     35         case 1:
     36             printf("通讯录的建立
    ");
     37             head = CreateList();
     38             break;
     39         case 2:
     40             printf("通讯录结点的插入
    ");
     41             p = (ListNode*) malloc(sizeof(ListNode));
     42             scanf("%s %s %s %s %s", &p->data.num, &p->data.name, &p->data.sex, &p->data.phone, &p->data.addr);
     43             InsertNode(head, p);
     44             break;
     45         case 3:
     46             printf("通讯录结点的查询
    ");
     47             p = LinkFind(head);
     48             if (p != NULL)
     49             {
     50                 printf("编号 姓名 性别 联系电话 地址
    ");
     51                 printf("%s %s %s %s %s", p->data.num, p->data.name, p->data.sex, p->data.phone, p->data.addr);
     52             }
     53             else
     54                 printf("没查到要查询的通讯者!
    ");
     55             break;
     56         case 4:
     57             printf("通讯录结点的删除
    ");
     58             DelNode(head);
     59             break;
     60         case 5:
     61             printf("通讯录链表的输出
    ");
     62             PrintList(head);
     63             break;
     64         case 0:
     65             printf("再见!
    ");
     66             return;
     67         }
     68     }
     69 
     70 }
     71 
     72 int menu_select()
     73 {
     74     int sn;
     75     printf("   通讯录管理系统
    ");
     76     printf("==================
    ");
     77     printf("  1,通讯录的建立
    ");
     78     printf("  2,通讯录结点的插入
    ");
     79     printf("  3,通讯录结点的查询
    ");
     80     printf("  4,通讯录结点的删除
    ");
     81     printf("  5,通讯录链表的输出
    ");
     82     printf("  0,退出管理系统
    ");
     83     printf("==================
    ");
     84     printf("请选择0---5
    ");
     85     scanf("%d",&sn);
     86 
     87     return sn;
     88 }
     89 LinkList CreateList(void)
     90 {
     91     LinkList head = (ListNode*) malloc(sizeof(ListNode));
     92     ListNode *p, *rear;
     93     int flag = 1;
     94     rear = head;
     95     while (flag)
     96     {
     97         p = (ListNode*) malloc(sizeof(ListNode));
     98         printf("编号(4),姓名(8),性别,电话(11),地址(31)
    ");
     99         scanf("%s %s %s %s %s", &p->data.num, &p->data.name, &p->data.sex, &p->data.phone, &p->data.addr);
    100         rear->next = p;
    101         rear = p;
    102 
    103         printf("继续输入吗?(1/0):");
    104         scanf("%d", &flag);
    105     }
    106     rear->next = NULL;
    107     return head;
    108 }
    109 
    110 void InsertNode(LinkList head, ListNode*p)
    111 {
    112     ListNode*p1, *p2;
    113     p1 = head;
    114     p2 = p1->next;
    115     while (p2 != NULL && strcmp(p2->data.num, p->data.num) < 0)
    116     {
    117         p1 = p2;
    118         p2 = p2->next;
    119     }
    120     p1->next = p;
    121     p->next = p2;
    122 }
    123 
    124 ListNode *LinkFind(LinkList head)
    125 {
    126     ListNode*p;
    127     char num[5];
    128     char name[9];
    129     int xz;
    130     printf("===========
    ");
    131     printf("1,按编号查询
    ");
    132     printf("2,按姓名查询
    ");
    133     printf("===========
    ");
    134     printf("请选择:");
    135     p = head->next;
    136     scanf("%d", &xz);
    137     if (xz == 1)
    138     {
    139         printf("请输入查找者的编号:");
    140         scanf("%s", &num);
    141         while (p && strcmp(p->data.num,num) < 0)
    142             p = p->next;
    143         if (p ==  NULL && strcmp(p->data.num, num) > 0)
    144             p = NULL;
    145     }
    146     else
    147         if (xz == 2){
    148             printf("请输入要查找者的姓名:
    ");
    149             scanf("%s", &name);
    150             while (p && strcmp(p->data.name, name) != 0);
    151             p = p->next;
    152         }
    153         return p;
    154 }
    155 
    156 void DelNode(LinkList head)
    157 {
    158     char jx;
    159     ListNode *p, *q;
    160     p = LinkFind(head);
    161     if (p == NULL){
    162         printf("没有查到想要删除的通讯者
    ");
    163         return;
    164     }
    165     printf("真的要删除该结点吗?(y/n):");
    166     scanf("%c", &jx);
    167     if (jx == 'y' || jx == 'Y')
    168     {
    169         q = head;
    170         while (q!=NULL && q->next != p)
    171             q = q->next;
    172         q->next = p->next;
    173         free(p);
    174         printf("通讯者已被删除
    ");
    175     }
    176 }
    177 
    178 void PrintList(LinkList head)
    179 {
    180     ListNode*p;
    181     p = head->next;
    182     printf("编号  姓名 性别 联系电话 地址
    ");
    183     printf("-----------------------------
    ");
    184     while (p != NULL)
    185     {
    186         printf("%s,%s,%s,%s,%s
    ", p->data.num, p->data.name, p->data.sex, p->data.phone, p->data.addr);
    187         printf("-------------------------
    ");
    188         p = p->next;
    189     }
    190 }
  • 相关阅读:
    正向代理和反向代理的区别
    response对象和request对象详解
    非controller层获取response和request对象
    Java中的Lock与synchronized
    如何解决jeecgBoot前端运行项目之后无法获取验证码的问题
    怎么定义一个自己的vue组件
    前端集成方案——理论(二)
    javascript基础-ajax
    网页中文乱码
    javascript基础-事件2
  • 原文地址:https://www.cnblogs.com/Zblogs/p/3440514.html
Copyright © 2020-2023  润新知