kjvba

来源:互联网 发布:mac怎么使用百度云 编辑:程序博客网 时间:2024/06/04 23:32
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "addresslist.h"
int tration(char *p)
{
 if(strcmp("ID",p) == 0)
 {
  return 1;
 }
 if(strcmp("name",p) == 0)
 {
  return 2;
 }
 if(strcmp("phone",p) == 0)
 {
  return 3;
 }
 if(strcmp("address",p) == 0)
 {
  return 4;
 }
 if(strcmp("companynumber",p) == 0)
 {
  return 5;
 }
}
int main()
{
 int ret;
 char choice;
 memberlist member1;
 member p;
 member a[10];
 p.name = (char *)malloc(sizeof(char) * 10);
 p.homenum = (char *)malloc(sizeof(char) * 50);
 p.address = (char *)malloc(sizeof(char) * 50);
 p.companynum = (char *)malloc(sizeof(char) * 50);
 p.id = (char *)malloc(sizeof(char) * 50);
 Initlist(&member1);
 
 while(1)
 {
  system("clear");
  headdisplay();
  printf("please input your choice :\n");
  scanf(" %c",&choice);
  system("clear");
  switch(choice)
  {
   case('A'):{
      input(&p,member1);
      Listtail(&member1,p);
      printf("input success!\n");
      printf("please press 1 exit ^_^\n");
      exit1();
      break;
     }
   case('B'):{
      Listtraverse(member1,a);
      printf("please press 1 exit ^_^\n");
      exit1();
      break;
     }
   case('C'):{
      char *a = (char *)malloc(sizeof(char) * 50);
      printf("please input you need's member:\n");
      scanf("%s",a);
         ret =  Listsearch(member1,a);
      if(ERROR == ret)
      {
       printf("Don't search %s!\n",a);
      }
      printf("please press 1 exit ^_^\n");
      exit1();
      break;
     }
   case('D'):{
      char *b = (char *)malloc(sizeof(char) * 50);
      printf("please input you need's delete member:\n");
      scanf("%s",b);
      ret = Listdelete(member1,b);
      if(ERROR == ret)
      {
       printf("system can't find the name! #_#\n\n\n");
      }
      else
      {
       printf("delete success!\n\n\n");
      }
      printf("please press 1 exit ^_^\n");
      exit1();
      break;
     }
   case('E'):{
      char *c = (char *)malloc(sizeof(char) * 50);
      char *d = (char *)malloc(sizeof(char) * 50);
      printf("please input you need's member:\n");
      scanf("%s",c);
         ret =  Listsearch(member1,c);
      if(ERROR == ret)
      {
       printf("Don't search %s!\n",a);
       printf("please press 1 exit ^_^\n");
          exit1();
          break;
      }
      printf("Now,please input what you want to mend :^_^\n");
      scanf("%s",d);
      switch(tration(d))
      {
       case (1):{
           char *id = (char *)malloc(sizeof(char) * 50);
           printf("The new ID is :");
           scanf("%s",id);
           Mendlist1(&member1,c,id);
           free(id);
           break;
          }
       case (2):{
           char *name = (char *)malloc(sizeof(char) * 50);
           printf("The new name is :");
           scanf("%s",name);
           Mendlist2(&member1,c,name);
           free(name);
           break;
          }
       case (3):{
           char *phone = (char *)malloc(sizeof(char) * 50);
           printf("The new phone is :");
           scanf("%s",phone);
           Mendlist3(&member1,c,phone);
           free(phone);
           break;
          }
       case (4):{
           char *address = (char *)malloc(sizeof(char) * 50);
           printf("The new address is :");
           scanf("%s",address);
           Mendlist4(&member1,c,address);
           free(address);
           break;
          }
       case (5):{
           char *companynum = (char *)malloc(sizeof(char) * 50);
           printf("The new company number is :");
           scanf("%s",companynum);
           Mendlist5(&member1,c,companynum);
           free(companynum);
           break;
          }
      }
        printf("mend success!\n");
        printf("please press 1 exit ^_^\n");
        exit1();
        break;
       }
   case('F'):{
        exit(0);
        break;
       }
  }
 }
 return 0;
}

原创粉丝点击