C language to achieve the communication management system design

  • 2020-06-01 10:36:51
  • OfStack

In this paper, the example for you to share the C language to achieve the communication management system of the specific code, for your reference, the specific content is as follows


#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct{
 char num[5];
 char name[9];
 char sex[9];
 char phone[13];
 char addr[31];
}DataType;
typedef struct node{
 DataType data;
 struct node*next;
} ListNode, *LinkList;

LinkList head;
ListNode *p;

int menu_select();
LinkList CreateList(void);
void InsertNode(LinkList head,ListNode *p);
ListNode *ListFind(LinkList head);
void DelNode(LinkList head);
void printList(LinkList head);
void ChangeNode(LinkList head);

int main(void){
 for(; ;){
  switch(menu_select()){
   case 1:
    printf("**********************\n");
    printf("*  tong   -   record   chain   table   build   state  *\n");
    printf("***********************\n");
    head=CreateList();
    break;
   case 2:
    printf("*********************\n");
    printf(" tong   -   record   The letter   Interest rates   the   insert   Into the  *\n");
    printf("*********************\n");
    printf(" Please enter the number, name, gender, telephone and address  \n");
    printf("**********************************\n");
    p=(ListNode*)malloc(sizeof(ListNode));
    scanf("%s%s%s%s%s",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
    InsertNode(head,p);
    break;
   case 3:
    printf("***********************\n");
    printf(" tong   -   record   the   check   polling  *\n");
    p=ListFind(head);
    if(p!=NULL){
     printf(" Serial number   The name   gender   The phone   address  \n");
     printf("-------------------------- \n");
     printf("%s%s%s%s%s",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
}    else
     printf(" Did not check to inquire the communicator! \n");
     break;
   case 4:
    printf("***********************\n");
    printf("*  tong   -   those   The letter   Interest rates   the   repair   change  *\n");
    printf("**********************\n");
    ChangeNode(head);
    break;
   case 5:
    printf("************************\n");
    printf(" tong   -   record   the   The letter   Interest rates   delete   In addition to  *\n");
    printf("*************************\n");
    DelNode(head);
    break;
   case 6:
    printf("************************\n");
    printf(" tong   -   record   chain   table   the   Lose,   Out of the  *\n");
    printf("*************************\n");
    printList(head);
    break;
   case 0:
    printf("\t  again   See you! \n");
    return 0;
 }
 }

}
int menu_select(){
 int sn;
 printf("  Address book management system \n");
 printf("========================\n");
 printf(" 1.  The establishment of address book linked list \n");
 printf(" 2.  The insertion of address book information \n");
 printf(" 3.  A query for address book information \n");
 printf(" 4.  Modification of address book information \n");
 printf(" 5.  The deletion of address book information \n");
 printf(" 6.  The output of address book information \n");
 printf(" 0.  Exit management system \n");
 printf("  please   choose   Choose the  0 - 6 : ");
 for(; ;){
  scanf("%d",&sn);
  if(sn<0 || sn>6)
   printf("\n\t Enter error, re - select 0-6 : ");
  else
   break;
}
 return sn;


}
LinkList CreateList(void){
 LinkList head=(ListNode *)malloc(sizeof(ListNode));
 ListNode *p,*rear;
 char flag='y';
 rear=head;
 while(flag=='y'){
  p=(ListNode *)malloc(sizeof(ListNode));
  printf(" Please enter the number, name, gender, telephone and address in sequence \n");
  printf("--------------------------------------\n");
  scanf("%s%s%s%s%s",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
  rear->next=p;
  rear=p;
  printf(" Continue typing?   ( y/n ) :");
  getchar();
  scanf("%c",&flag);
}

 rear->next=NULL;
 return head;

} 
void InsertNode(LinkList head,ListNode *p){
 ListNode *p1,*p2;
 p1=head;
 p2=p1->next;
 while(p2!=NULL && strcmp(p2->data.num,p->data.num)<0)
 {
  p1=p2;
  p2=p2->next;

 }

 p1->next=p;
 p->next=p2;

} 
ListNode *ListFind(LinkList head){
 ListNode *p; 
 char num[5];
 char name[9]; 
 int xz=0;
 printf("===========\n");
 printf("1.  Query by number  \n");
 printf("2.  Search by name  \n");
 printf("===========\n");
 printf("  Please select: ");
 p=head->next;
 scanf("%d",&xz);
 if(xz==1){
  printf(" Please enter the number of the inquirer :");
  scanf("%s",num);
  while(p && strcmp(p->data.num,num)<0)
   p=p->next;
  if(p==NULL||strcmp(p->data.num,num)>0)
   p=NULL;

}
 else
  if(xz==2) {
   printf(" Please enter the name of the person you want to inquire: ");
   scanf("%s",name);
   while(p && strcmp(p->data.name,name)!=0)
    p=p->next;    
 }

 return p;
}
void DelNode(LinkList head){
 char jx;
 ListNode *p,*q;
 p=ListFind(head);
 if(p==NULL){
  printf(" No sender to delete was found !\n");
  return;

 }
 printf(" Do you really want to delete the node ?(y/n):");
 getchar();
 scanf("%c",&jx);
 if(jx=='y'||jx=='Y'){
  q=head;
  while(q!=NULL && q->next!=p)
   q=q->next;
  q->next=p->next;
  free(p);
  printf(" The address book has been deleted !\n");
 }
}
void printList(LinkList head){
 ListNode *p;
 p=head->next;
 printf(" Serial number   The name   gender   The phone   address \n");
 printf("--------------------------------------\n");
 while(p!=NULL)
 {
  printf("%s%s%s%s%s\n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
  printf("--------------------------------\n");
  p=p->next;
 }
} 
void ChangeNode(LinkList head){
 ListNode *p;
 p=ListFind(head);
 if(p!=NULL){
  printf(" Serial number   The name   gender   The phone   address \n");
  printf("--------------------------------------\n");
  scanf("%s%s%s%s%s\n",p->data.num,p->data.name,p->data.sex,p->data.phone,p->data.addr);
  printf("--------------------------------------\n");
  printf(" Enter the correct contact number for the person in the address book   Mailing address: \n The middle is separated by a space mark \n");
  scanf("%s%s",p->data.phone,p->data.addr);

}
 else
  printf(" Did not find the address book to query! \n");
}

For more information, please refer to the topic "management system development".


Related articles: