久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6458|回復: 0
打印 上一主題 下一主題
收起左側

C語言通訊錄管理系統的設計

[復制鏈接]
跳轉到指定樓層
樓主
基于C語言的通訊錄設計

完整代碼下載:
個人通訊錄系統.rar (237.77 KB, 下載次數: 19)


部分源碼預覽:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5.     struct person
  6.          {
  7.                char name[15];
  8.                char type[15];
  9.            int nianling;
  10.            long int youbian;
  11.                char addr[50];
  12.                char celephone[22];
  13.                char homephone[22];
  14.                   char company[20];
  15.                char email[40];
  16.                char QQ[22];
  17.         }communication[500];
  18.    int num=0;//*外部變量num為文件中的紀錄數*//
  19.    FILE *fp;
  20.    void mainmenu();//*主菜單*//
  21.    void newrecord();//新添紀錄*//
  22.    void xiugaimenu();//*修改菜單*//
  23.    void xiugaibyname();//*按姓名修改*//
  24.    void xiugaibycelephone();//*按手機號碼修改*//
  25.    void xiugaixiangmu(int a);//*修改項目*//
  26.    void searchmenu();//*查詢菜單*//
  27.    void searchbyname();//*按姓名查詢*//
  28.    void searchbycelephone();//*按手機號碼查詢*//
  29.    void searchbyhomephone();//*按固定電話號碼查詢*//
  30.    void searchbyqq();//*按QQ查詢*//
  31.    void deletemenu();//*刪除菜單*//
  32.    void deleteall();//*刪除所有信 息*//
  33.    void deleteone();//*刪除單個*//
  34.    void showall();//*輸 出 全 部 信 息*//
  35.    void readfromfile();//*讀取文件*//
  36.    void writetofile();//*寫入文件*// /
  37.    void deletebycelephone();  //*按手機號碼刪除*//
  38.    void deletebyname();//*按姓名刪除*/
  39.    void listbycelephone();//*按手機號碼排序*//
  40.    void listbyname();//*按姓名排序*//
  41.    void listmenu();//*排序菜單*//
  42.    


  43. void main()//*主函數*//
  44. {
  45.         system("cls");
  46.         readfromfile();
  47.         while (1)
  48.         {
  49.                 mainmenu();
  50.         }
  51. } //*主函數結束*//





  52. void mainmenu()//*主菜單函數*//
  53. {
  54.         int a;
  55.         system("cls");
  56.         system("color 2a");
  57.         printf("\n            **************您 好! 歡 迎 使 用 通 訊 錄************\n");
  58.         printf("            *             1: 添 加 通 訊 錄 信 息               *\n");
  59.         printf("            *             2: 查 詢 通 訊 錄 信 息               *\n");
  60.         printf("            *             3: 刪 除 通 訊 錄 信 息               *\n");  
  61.         printf("            *             4: 修 改 通 訊 錄 信 息               *\n");   
  62.         printf("            *             5: 通 訊 錄 信 息 排 序               *\n");
  63.         printf("            *             6: 輸 出 通 訊 錄 信 息               *\n");   
  64.         printf("            *             7: 保存文件(添加后必選)             *\n");
  65.         printf("            *             8: 讀 取 通 訊 錄 文 件               *\n");
  66.         printf("            *             9: 刪 除 所 有 聯 系 人               *\n");
  67.         printf("            *             0: 退 出 通 訊 錄 系 統               *\n");
  68.         printf("            *****************************************************\n");
  69.         printf("\n            請輸入您的數字選擇:    ");
  70.         loop1: scanf("%d",&a);
  71.         switch (a)
  72.         {

  73.                 case 1:newrecord();break;
  74.                 case 2:searchmenu();break;
  75.                 case 3:deletemenu();break;
  76.                 case 4:xiugaimenu();break;
  77.                 case 5:listmenu();break;
  78.                 case 6:showall();break;
  79.                 case 7:writetofile();break;
  80.                 case 8:readfromfile();break;
  81.                 case 9:deleteall();break;
  82.                 case 0:exit(0);
  83.                 default:printf("對不起!您的輸入有誤!請重新輸入:   ");goto loop1;
  84.         }
  85. }


  86. void newrecord()//*添加紀錄*//
  87. {
  88.      int a;
  89.      system("cls");
  90.      system("color 2a");
  91. loop:          printf("\n\n\n\n\t\t  請輸入您要添加的聯系人的信息: \n");        
  92.             printf("\n請輸入姓名(小于15個漢字):\n");
  93. name: scanf("%s",&communication[num].name);
  94.           if(strlen(communication[num].name)>15)
  95.            {
  96.                   printf("對不起!您的輸入有誤!請重新輸入");
  97.                   goto name;
  98.            }
  99.       printf("\n請輸入該聯系人類別:\n");
  100. type:  scanf("%s",&communication[num].type);
  101.           printf("\n請輸入年齡(0-110之間):\n");
  102. nianling:          scanf("%d",&communication[num].nianling);
  103.       if(communication[num].nianling<0||communication[num].nianling>110)
  104.        {
  105.                  printf("對不起!您的輸入有誤!請重新輸入");
  106.                  goto  nianling;
  107.        }
  108.       printf("\n請輸入郵編(5-6個數字):\n");
  109. youbian:    scanf("%d",&communication[num].youbian);
  110.       if(communication[num].youbian<10000||communication[num].youbian>999999)
  111.           {
  112.               printf("對不起!您的輸入有誤!請重新輸入");
  113.                   goto  youbian;
  114.           }
  115.           printf("\n請輸入地址(0-50個漢字):\n");
  116. addr:        scanf("%s",&communication[num].addr);
  117.           if(strlen(communication[num].addr)>50||strlen(communication[num].addr)<0)
  118.           {
  119.                   printf("對不起!您的輸入有誤!請重新輸入:\n");
  120.                   goto addr;
  121.           }
  122.           printf("\n請輸入手機號碼(11個數字):\n");
  123. celephone:   scanf("%s",&communication[num].celephone);
  124.           if(strlen(communication[num].celephone)!=11)
  125.           {
  126.                   printf("對不起!您的輸入有誤!請重新輸入\n");
  127.                   goto celephone;
  128.           }          
  129.           printf("\n請輸入固定電話(8-11個數字):\n");
  130. homephone:        scanf("%s",&communication[num].homephone);
  131.           printf("\n請輸入公司名稱:\n");
  132. company:    scanf("%s",&communication[num].company);
  133.           printf("\n輸入電子郵箱(4-30個字符):\n");
  134. email:        scanf("%s",&communication[num].email);
  135.         if(strlen(communication[num].email)>30||strlen(communication[num].email)<4)
  136.           {
  137.                   printf("對不起!您的輸入有誤!請重新輸入");
  138.                   goto email;
  139.           }
  140.         printf("\n輸入QQ號碼:\n");
  141. QQ:        scanf("%s",&communication[num].QQ);
  142.         num++;
  143.         printf("\n是否繼續添加?\n");
  144.         printf("\n請按1和2(1代表繼續;2代表不繼續)\n");
  145.     printf("請輸入您的選擇  ");
  146.     scanf("%d",&a);
  147.     if(a==1)
  148.     {
  149.           goto loop;
  150.     }
  151.     else
  152.     {
  153.            return;
  154.     }
  155. }




  156. void searchmenu()//*查詢菜單*//
  157. {
  158.         int a;
  159.         system("cls");
  160.         system("color 2a");
  161.         printf("\n\t********歡   迎   使    用    查    詢    菜   單********");
  162.         printf("\n\t\t              >>> 1-按手機號碼查詢");
  163.         printf("\n\t\t              >>> 2-按姓名查詢");
  164.         printf("\n\t\t              >>> 3-按固定電話查詢");
  165.         printf("\n\t\t              >>> 4-按QQ查詢");
  166.     printf("\n\t\t              >>> 5-返回主菜單");
  167.         printf("\n\t\t");
  168.     printf("       >>> 請輸入您的選擇:");
  169.         scanf("%d",&a);
  170.         switch (a)
  171.         {  
  172.                 case 1:searchbycelephone();break;
  173.                 case 2:searchbyname();break;
  174.                 case 3:searchbyhomephone();break;
  175.                 case 4:searchbyqq();break;       
  176.                 case 5:mainmenu();break;
  177.         }
  178. }


  179. void searchbycelephone()//*按手機號碼查詢*//
  180. {
  181.         int mark=0;
  182.         int i,j;
  183.         int a=0;
  184.         char celephone[11];
  185.         printf("\n               按手機號碼查找                \n");
  186.         printf("\n請輸入手機號碼:\n");
  187.         scanf("%s",celephone);
  188.         for(i=0;i<num;i++)
  189.         {
  190.                 if (strcmp(communication[i].celephone,celephone)==0)
  191.                 {
  192.                         printf("\n*****************以下是您查找的聯系人的信息***************");
  193.                         printf("\n________________________________");
  194.                         printf("\n     名字:    %s",communication[i].name);
  195.                         printf("\n     類別:    %s",communication[i].type);
  196.                         printf("\n     年齡:    %d",communication[i].nianling);
  197.                         printf("\n     郵編:    %ld",communication[i].youbian);
  198.                         printf("\n     地址:    %s",communication[i].addr);
  199.                         printf("\n     手機號碼:%s",communication[i].celephone);
  200.                         printf("\n     固定電話:%s",communication[i].homephone);
  201.                         printf("\n     公司名稱:%s",communication[i].company);
  202.                         printf("\n     電子郵件:%s",communication[i].email);
  203.                         printf("\n     QQ號碼:%s",communication[i].QQ);
  204.                         printf("\n________________________________");
  205.                     printf("\n請按任意數字鍵并回車返回主菜單");
  206.                     mark++;
  207.                     scanf("%d",&j);
  208.                     return;
  209.                 }
  210.         }
  211.         if (mark==0)
  212.         {
  213.                 printf("\n對不起!沒有該聯系人的信息!");
  214.                 printf("\n請按任意數字鍵返回主菜單");
  215.                 scanf("%d",&j);
  216.                 return;
  217.         }
  218. }



  219. void searchbyname()//*按姓名查詢*//
  220. {
  221.         int mark=0;
  222.         int i,j,findmark=0;
  223.         int a=0;
  224.         char name[15];
  225.         printf("\n          ***********************按 姓 名 查 找***********************");
  226.         printf("\n請輸入姓名:");
  227.         scanf("%s",name);
  228.         for(i=a;i<num;i++)
  229.         {
  230.                 if (strcmp(communication[i].name,name)==0)
  231.                 {
  232.             findmark++;
  233.                         printf("\n\t\t************以下是您查找的聯系人的信息************");
  234.                         printf("\n\t\t________________________________");
  235.                         printf("\n\t\t   名字:    %s",communication[i].name);
  236.                         printf("\n\t\t   類別:    %s",communication[i].type);
  237.                         printf("\n\t\t   年齡:    %d",communication[i].nianling);
  238.                         printf("\n\t\t   郵編:    %ld",communication[i].youbian);
  239.                         printf("\n\t\t   地址:    %s",communication[i].addr);
  240.                         printf("\n\t\t   手機號碼:%s",communication[i].celephone);
  241.                         printf("\n\t\t   固定電話:%s",communication[i].homephone);
  242.                         printf("\n\t\t   公司名稱:%s",communication[i].company);
  243.                         printf("\n\t\t   電子郵件:%s",communication[i].email);
  244.                         printf("\n\t\t   QQ號碼:%s",communication[i].QQ);
  245.                         printf("\n\t\t________________________________");
  246.                         if ((i+1)<num)
  247.                         {
  248.                                 printf("\n是否繼續查找相同名字的聯系人的信息?(1代表繼續;2代表不繼續)");
  249.                                 scanf("%d",&j);
  250.                                 if (j==1)
  251.                                 {
  252.                                         a=i;
  253.                     mark++;
  254.                                         continue;
  255.                                 }
  256.                                 else
  257.                                         break;
  258.                         }
  259.                         else
  260.                         {
  261.                  printf("\n請按任意數字鍵返回主菜單");
  262.                          scanf("%d",&j);
  263.                          return;
  264.                         }
  265.                 }
  266.         }
  267.         if(mark!=0)
  268.         {
  269.                 printf("\n對不起! 沒有相同名字的該聯系人的信息!!");
  270.                 printf("\n請按任意數字鍵返回主菜單");
  271.                 scanf("%d",&j);
  272.                 return;
  273.         }
  274.         else if(findmark==0)
  275.         {
  276.                 printf("\n對不起!沒有該聯系人的信息!");
  277.                 printf("\n請按任意數字鍵返回主菜單");
  278.                 scanf("%d",&j);
  279.                 return;  
  280.         }
  281. }



  282. void searchbyhomephone()//*按固定電話查詢*//
  283. {
  284.         int mark=0;
  285.         int i,j;
  286.         int a=0;
  287.         char homephone[11];
  288.         printf("\n\t    ******************按 固 定 電 話 查 找******************");
  289.         printf("\n請輸入固定電話:");
  290.         scanf("%s",homephone);
  291.         for(i=0;i<num;i++)
  292.         {
  293.                 if (strcmp(communication[i].homephone,homephone)==0)
  294.                 {
  295.                         printf("\n\t\t**********以下是您要查找的聯系人的信息**********");
  296.                         printf("\n\t\t________________________________");
  297.                         printf("\n\t\t   名字:    %s",communication[i].name);
  298.                         printf("\n\t\t   類別:    %s",communication[i].type);
  299.                         printf("\n\t\t   年齡:    %d",communication[i].nianling);
  300.                         printf("\n\t\t   郵編:    %ld",communication[i].youbian);
  301.                         printf("\n\t\t   地址:    %s",communication[i].addr);
  302.                         printf("\n\t\t   手機號碼:%s",communication[i].celephone);
  303.                         printf("\n\t\t   固定電話:%s",communication[i].homephone);
  304.                         printf("\n\t\t   公司名稱:%s",communication[i].company);
  305.                         printf("\n\t\t   電子郵件:%s",communication[i].email);
  306.                         printf("\n\t\t   QQ號碼:  %s",communication[i].QQ);
  307.                         printf("\n\t\t________________________________");
  308.             printf("\n\t\t請按任意數字鍵返回主菜單");
  309.                         mark++;
  310.                     scanf("%d",&j);
  311.                     return;
  312.                 }
  313.         }
  314.         if (mark==0)
  315.         {
  316.                 printf("\n\t\t對不起!沒有該聯系人的信息!");
  317.                 printf("\n\t\t請按任意數字鍵返回主菜單");
  318.                 scanf("%d",&j);
  319.                 return;  
  320.         }
  321. }



  322. void searchbyqq()//*按QQ查詢*//
  323. {
  324.         int mark=0;
  325.         int i,j;
  326.         int a=0;
  327.         char QQ[22];
  328.         printf("\n\t**********************按 QQ 號 碼 查 找***********************\n");
  329.         printf("\n請輸入QQ號碼:");
  330.         scanf("%s",&QQ);
  331.         for(i=0;i<num;i++)
  332.         {
  333.                 if (strcmp(communication[i].QQ,QQ)==0)
  334.                 {
  335.                         printf("\n\t***********以下是您查找的聯系人的信息**********");
  336.                         printf("\n\t\t________________________________");
  337.                         printf("\n\t\t   名字:    %s",communication[i].name);
  338.                         printf("\n\t\t   類別:    %s",communication[i].type);
  339.                         printf("\n\t\t   年齡:    %d",communication[i].nianling);
  340.                         printf("\n\t\t   郵編:    %ld",communication[i].youbian);
  341.                         printf("\n\t\t   地址:    %s",communication[i].addr);
  342.                         printf("\n\t\t   手機號碼:%s",communication[i].celephone);
  343.                         printf("\n\t\t   固定電話:%s",communication[i].homephone);
  344.                         printf("\n\t\t   公司名稱:%s",communication[i].company);
  345.                         printf("\n\t\t   電子郵件:%s",communication[i].email);
  346.                         printf("\n\t\t   QQ號碼:  %s",communication[i].QQ);
  347.                         printf("\n\t\t________________________________");
  348.             printf("\n\t\t請按任意數字鍵返回主菜單");
  349.                     mark++;
  350.                     scanf("%d",&j);
  351.                     return;
  352.                 }
  353.         }
  354.         if (mark==0)
  355.         {
  356.                 printf("\n\t\t對不起!沒有該聯系人的信息!");
  357.                 printf("\n\t\t請按任意數字鍵返回主菜單");
  358.                 scanf("%d",&j);
  359.                 return;
  360.         }
  361. }




  362. void deletemenu()//*刪除菜單*//
  363. {  
  364.     int i,j;
  365.     system("cls");
  366.         system("color 3b");   
  367.         if(num==0)
  368.         {
  369.                 printf("\n\t\t對不起!文件中無任何紀錄!");
  370.                 printf("\n\t\t請先添加個人信息!");
  371.                 printf("\n\t\t請按任意數字鍵并回車返回主菜單");
  372.                 scanf("%d",&j);
  373.                 return;
  374.         }
  375.         else
  376.         {
  377.            printf("\n\t\t                      刪 除 菜 單                   ");
  378.        printf("\n\t\t                  >>> 1-刪除單個                    ");       
  379.            printf("\n\t\t                  >>> 2-返回主菜單                   ");
  380.            printf("\n\t\t                                                 ");
  381.            printf("\n\t\t請輸入您的數字選擇:    ");
  382.            loop4: scanf("%d",&i);
  383.            switch (i)
  384.            {
  385.                 case 1:deleteone();break;
  386.                 case 2:mainmenu();break;
  387.                 default:printf("對不起!您的輸入有誤!請重新輸入:   ");goto loop4;
  388.            }
  389.         }
  390. }



  391. void deleteone()//*刪除單個*//
  392. {
  393.         int i;
  394.         printf("\n\t\t1-按手機號碼刪除 2-按姓名刪除");
  395.         printf("\n\t\t請輸入您的選擇:");
  396.         loop5:scanf("%d",&i);;
  397.         switch (i)
  398.         {
  399.         case 1:deletebycelephone();break;
  400.         case 2:deletebyname();break;
  401.     default:printf("對不起!您的輸入有誤!請重新輸入:   ");goto loop5;
  402.         }
  403. }


  404. void deletebyname()//姓名刪除*//
  405. {
  406.         int a=0;
  407.         int findmark=0;
  408.         int i,j,k;
  409.         int deletemark=0;
  410.         char name[15];
  411.         printf("\n\t\t請輸入您要刪除的聯系人的姓名:");
  412.         scanf("%s",name);
  413.         for (i=a;i<num;i++)
  414.         {
  415.                 if (strcmp(communication[i].name,name)==0)
  416.                 {
  417.                         printf("\n\t\t以下是您要刪除的聯系人的紀錄:");
  418.                         findmark++;
  419.                         printf("\n\t\t________________________________");
  420.                         printf("\n\t\t   名字:    %s",communication[i].name);
  421.                         printf("\n\t\t   類別:    %s",communication[i].type);
  422.                         printf("\n\t\t   年齡:    %d",communication[i].nianling);
  423.                         printf("\n\t\t   郵編:    %ld",communication[i].youbian);
  424.                         printf("\n\t\t   地址:    %s",communication[i].addr);
  425.                         printf("\n\t\t   手機號碼:%s",communication[i].celephone);
  426.                         printf("\n\t\t   固定電話:%s",communication[i].homephone);
  427.                         printf("\n\t\t   公司名稱:%s",communication[i].company);
  428.                         printf("\n\t\t   電子郵件:%s",communication[i].email);
  429.                         printf("\n\t\t   QQ號碼:  %s",communication[i].QQ);
  430.                         printf("\n\t\t________________________________");
  431.                         printf("\n\t\t是否刪除?(1代表是;2代表否)\n");
  432.                         printf("\n\t\t請輸入您的數字選擇:    ");
  433.                         scanf("%d",&k);
  434.                         if(k==1)
  435.                         {
  436.                                 for (j=i;j<num-1;j++) //*紀錄移動,從communication數組中刪除之*//
  437.                                 communication[j]=communication[j+1];
  438.                                 num--;
  439.                                 deletemark++;
  440.                                 printf("\n\t\t刪除成功");
  441.                                 if((i+1)<num)
  442.                                 {
  443.                                         printf("\n\t\t是否繼續刪除相同姓名的聯系人的信息?(1代表刪除;2代表不刪除)");
  444.                                 printf("\n\t\t請輸入您的數字選擇:    ");
  445.                                 scanf("%d",&k);
  446.                                 if(k=1)
  447.                                         {
  448.                                                 a=i;
  449.                                                 findmark++;
  450.                                                 continue;
  451.                                         }
  452.                                 }
  453.                                 printf("\n\t\t是否繼續刪除?(1代表繼續;2代表不繼續)");
  454.                 printf("\n\t\t請輸入您的數字選擇:    ");
  455.                 scanf("%d",&k);
  456.                 if(k==1)
  457.                                    deleteone();
  458.                                 else
  459.                                 break;
  460.                         }
  461.                 }       
  462.                 else
  463.                 continue;
  464.         }
  465.         if((deletemark==0)&&(findmark==0))
  466.         {
  467.                 printf("\n\t\t對不起!沒有該聯系人的紀錄!");
  468.                 printf("\n\t\t是否繼續刪除?(1代表繼續;2代表不繼續)");
  469.                 printf("          請輸入您的數字選擇:    ");
  470.                 scanf("%d",&k);
  471.                 if(k==1)  
  472.                   deleteone();

  473.         }
  474.         else if(findmark!=0)
  475.         {
  476.                 printf("\n\t\t對不起!沒有重名信息!");
  477.                 printf("\n\t\t是否繼續刪除?(1代表繼續;2代表不繼續)");
  478.                 printf("          請輸入您的數字選擇:    ");
  479.                 scanf("%d",&k);
  480.             if(k==1)
  481.                    deleteone();
  482.         }
  483. }


  484. void deletebycelephone()//*按手機號碼刪除*//
  485. {
  486.         int i,j,h,m;
  487.         int deletemark=0;
  488.         char celephone[11];
  489.         printf("\n\t\t請輸入要刪除的聯系人的手機號碼:");
  490.         scanf("%s",celephone);
  491.         for(i=0;i<num;i++)
  492.         {
  493.                 if(strcmp(communication[i].celephone,celephone)==0)
  494.                 {
  495.                     deletemark++;
  496.                         printf("\n\t\t以下是您要刪除的聯系人的紀錄:");
  497.                         printf("\n\t\t________________________________");                  
  498.                         printf("\n\t\t   名字:    %s",communication[i].name);
  499.                         printf("\n\t\t   類別:    %s",communication[i].type);
  500.                         printf("\n\t\t   年齡:    %d",communication[i].nianling);
  501.                         printf("\n\t\t   郵編:    %ld",communication[i].youbian);
  502.                         printf("\n\t\t   地址:    %s",communication[i].addr);
  503.                         printf("\n\t\t   手機號碼:%s",communication[i].celephone);
  504.                         printf("\n\t\t   固定電話:%s",communication[i].homephone);
  505.                         printf("\n\t\t   公司名稱:%s",communication[i].company);
  506.                         printf("\n\t\t   電子郵件:%s",communication[i].email);
  507.                         printf("\n\t\t   QQ號碼:  %s",communication[i].QQ);
  508.                         printf("\n\t\t________________________________");
  509.                         printf("\n\t\t是否刪除?(1代表是;2代表否)\n");
  510.                         printf("          請輸入您的數字選擇:    ");
  511.                         scanf("%d",&h);
  512.                 if(h==1)
  513.                         {
  514.                                 for (j=i;j<num-1;j++) /*紀錄移動,從communication數組中刪除之*/
  515.                                 communication[j]=communication[j+1];
  516.                                 num--;  
  517.                                 printf("\n\t\t刪除成功");
  518.                                 printf("\n是否繼續刪除?(1代表繼續;2代表不繼續)\n");
  519.                                 printf("          請輸入您的數字選擇:    ");
  520.                                 scanf("%d",&h);
  521.                     if(h==1)  
  522.                                      deletebycelephone();
  523.                         }
  524.                 }
  525.         }
  526.         if(deletemark==0)
  527.         {
  528.                 printf("\n\t\t對不起!沒有該聯系人的紀錄!");
  529.                 printf("\n\t\t是否繼續刪除?(1代表繼續;2代表不繼續)\n");
  530.                 printf("          請輸入您的數字選擇:    ");
  531.                 scanf("%d",&m);
  532.             if(m==1)  
  533.                    deletebycelephone();
  534.         }
  535. }



  536. void xiugaimenu()//*修改菜單*//
  537. {
  538.         int i,j;
  539.     system("cls");
  540.         system("color 2a");
  541.         if(num==0)
  542.         {
  543.                 printf("\n\t\t對不起!文件中無任何紀錄!");
  544.                 printf("\n\t\t請按任意數字鍵返回主菜單");
  545.                 scanf("%d",&j);
  546.                 return;  
  547.         }
  548.         else
  549.         {
  550.             printf("\n\t\t 1-按姓名修改   2-按手機號碼修改\n");
  551.             printf("          請輸入您的數字選擇:    ");
  552.         loop6:scanf("%d",&i);
  553.             switch (i)
  554.             {
  555.               case 1:xiugaibyname();break;
  556.               case 2:xiugaibycelephone();break;
  557.               default:printf("對不起!您的輸入有誤!請重新輸入:   ");goto loop6;
  558.             }
  559.         }
  560. }



  561. void xiugaibyname()//*按姓名修改*//
  562. {
  563.         int a=0;
  564.         int findmark=0;
  565.         int xiugaimark=0;
  566.         int i,j;
  567.         char name[15];
  568.         printf("\n\t\t請輸入要修改聯系人的姓名:");
  569.         scanf("%s",name);
  570.         for (i=a;i<num;i++)
  571.         {
  572.                 if (strcmp(communication[i].name,name)==0)
  573.                 {
  574.                         printf("\n\t\t以下是您要修改的聯系人的紀錄:");
  575.                         findmark++;
  576.                         printf("\n\t\t________________________________");
  577.                         printf("\n\t\t   名字:    %s",communication[i].name);
  578.                         printf("\n\t\t   類別:    %s",communication[i].type);
  579.                         printf("\n\t\t   年齡:    %d",communication[i].nianling);
  580.                         printf("\n\t\t   郵編:    %ld",communication[i].youbian);
  581.                         printf("\n\t\t   地址:    %s",communication[i].addr);
  582.                         printf("\n\t\t   手機號碼:%s",communication[i].celephone);
  583.                         printf("\n\t\t   固定電話:%s",communication[i].homephone);
  584.                         printf("\n\t\t   公司名稱:%s",communication[i].company);
  585.                         printf("\n\t\t   電子郵件:%s",communication[i].email);
  586.                         printf("\n\t\t   QQ號碼:  %s",communication[i].QQ);
  587.                         printf("\n\t\t________________________________");
  588.                         printf("\n\t\t是否修改?(1代表是;2代表否)");
  589.                         printf("          請輸入您的數字選擇:    ");
  590.                         scanf("%d",&j);
  591.                         if (j==1)
  592.                         {
  593.                                 xiugaixiangmu(i);
  594.                                 xiugaimark++;
  595.                                 printf("\n\t\t修改成功");
  596.                                 if((i+1)<num)
  597.                                 {
  598.                                         printf("\n\t\t是否繼續修改相同姓名的聯系人的信息?(1代表繼續;2代表不繼續)");
  599.                                         printf("          請輸入您的數字選擇:    ");
  600.                                         scanf("%d",&j);
  601.                                         if (j==1)
  602.                                         {
  603.                                                 a=i;
  604.                                                 findmark++;
  605.                                                 continue;
  606.                                         }
  607.                                 }
  608.                                 printf("\n\t\t是否繼續修改?(1代表繼續;2代表不繼續)");
  609.                                 printf("          請輸入您的數字選擇:    ");
  610.                                 scanf("%d",&j);
  611.                                 if (j==1)
  612.                                 xiugaibyname();
  613.                                 return;
  614.                         }
  615.                 }
  616.         }
  617.         if ((xiugaimark==0)&&(findmark==0))
  618.         {
  619.                 printf("\n\t\t沒有該聯系人的紀錄");
  620.                 printf("\n\t\t是否繼續修改?(1代表繼續;2代表不繼續)");
  621.                 printf("          請輸入您的數字選擇:    ");
  622.                 scanf("%d",&j);
  623.                 if (j==1)
  624.                     xiugaibyname();
  625.                 return;
  626.         }
  627.         else if (findmark!=0)
  628.         {
  629.                 printf("\n\t\t沒有重名信息");
  630.                 printf("\n\t\t是否繼續修改?(1代表繼續;2代表不繼續)");
  631.                 printf("          請輸入您的數字選擇:    ");
  632.                 scanf("%d",&j);
  633.                 if (j==1)
  634.                 xiugaibyname();
  635.                 return;
  636.         }
  637. }



  638. void xiugaibycelephone()//*按手機號碼修改*//
  639. {
  640.         int findmark=0;
  641.         int i,j;
  642.         char celephone[11];
  643.         printf("\n\t\t請輸入要修改聯系人的手機號碼:");
  644.         scanf("%s",celephone);
  645.         for (i=0;i<num;i++)
  646.         {
  647.                 if (strcmp(communication[i].celephone,celephone)==0)
  648.                 {
  649.                         printf("\n\t\t以下是您要修改的聯系人的紀錄:");
  650.                         findmark++;
  651.                         printf("\n\t\t________________________________");
  652.                         printf("\n\t\t   名字:    %s",communication[i].name);
  653.                         printf("\n\t\t   類別:    %s",communication[i].type);
  654.                         printf("\n\t\t   年齡:    %d",communication[i].nianling);
  655.                         printf("\n\t\t   郵編:    %ld",communication[i].youbian);
  656.                         printf("\n\t\t   地址:    %s",communication[i].addr);
  657.                         printf("\n\t\t   手機號碼:%s",communication[i].celephone);
  658.                         printf("\n\t\t   固定電話:%s",communication[i].homephone);
  659.                         printf("\n\t\t   公司名稱:%s",communication[i].company);
  660.                         printf("\n\t\t   電子郵件:%s",communication[i].email);
  661.                         printf("\n\t\t   QQ號碼:  %s",communication[i].QQ);
  662.                         printf("\n\t\t________________________________");
  663.                         printf("\n\t\t是否修改?(1代表是;2代表否)");
  664.                         printf("          請輸入您的數字選擇:    ");
  665.                         scanf("%d",&j);
  666.                     if (j==1)
  667.                          {
  668.                                 xiugaixiangmu(i);
  669.                                 printf("\n\t\t修改成功");
  670.                                 printf("\n\t\t是否繼續修改?(1代表繼續;2代表不繼續)");
  671.                                 printf("          請輸入您的數字選擇:    ");
  672.                                 scanf("%d",&j);
  673.                         printf("          請輸入您的數字選擇:    ");
  674.                                 if (j==1)  
  675.                                   xiugaixiangmu(i);
  676.                                 break;
  677.                          }
  678.                 }  
  679.         }
  680.         if (findmark==0)
  681.         {
  682.                 printf("\n\t\t對不起!沒有該聯系人的紀錄!");
  683.                 printf("\n\t\t是否繼續修改?(1代表繼續;2代表不繼續)");
  684.                 printf("          請輸入您的數字選擇:    ");
  685.                 scanf("%d",&j);
  686.                 if (j==1)  
  687.                    xiugaibycelephone();
  688.                 return;
  689.         }
  690. }



  691. void xiugaixiangmu(int a)//*修改項目*//
  692. {
  693.         int i;
  694.         system("cls");
  695.         system("color c0");
  696.         printf("\n\t\t             請輸入您要修改的項目               ");
  697.         printf("\n\t\t\n");
  698.         printf("\n\t\t   1-手機號碼\n");
  699.         printf("\n\t\t   2-姓名\n");
  700.         printf("\n\t\t   3-固定電話\n");
  701.         printf("\n\t\t   4-QQ號碼\n");
  702.         printf("\n\t\t   5-地址\n");
  703.         printf("\n\t\t   6-郵編\n");
  704.         printf("\n\t\t   7-電子郵件\n");
  705.         printf("\n\t\t   8-回主菜單\n");
  706.         printf("\n\t\t\n");
  707.         printf("          請輸入您的數字選擇:    ");
  708.         scanf("%d",&i);
  709. loop9:        switch (i)
  710.         {

  711.                 case 1:printf("請輸入手機號碼:");
  712.                         scanf("%s",&communication[a].celephone);break;
  713.                 case 2:printf("請輸入姓名:");
  714.                         scanf("%s",&communication[a].name);break;
  715.                 case 3:printf("請輸入固定電話:");
  716.                         scanf("%s",&communication[a].homephone);break;
  717.                 case 4:printf("請輸入QQ號碼:");
  718.                         scanf("%s",&communication[a].QQ);break;
  719.                 case 5:printf("請輸入地址:");
  720.                         scanf("%s",&communication[a].addr);break;
  721.                 case 6:printf("請輸入郵編:");
  722.                         scanf("%s",&communication[a].youbian);break;
  723.                 case 7:printf("請輸入email:");
  724.                         scanf("%s",&communication[a].email);break;
  725.                 case 8:mainmenu();break;
  726.                 default: printf("對不起!您的輸入有誤!請重新輸入:   ");goto loop9;
  727.         }
  728. }


  729. void listmenu()//*排序菜單*//
  730. {
  731.     int i,j;
  732.     system("cls");
  733.         system("color b0");
  734.         if(num==0)
  735.         {
  736.                 printf("\n\t\t對不起,文件中無任何紀錄");
  737.                 printf("\n\t\t請按任意數字鍵返回主菜單");
  738.                 scanf("%d",&j);
  739.                 return;  
  740.         }
  741.         else
  742.         {
  743.            system("cls");
  744.            system("color 12");
  745.            printf("\n\t\t                 排   序   菜   單                 ");
  746.            printf("\n\t\t                >>> 1-按姓名排序                   ");
  747.            printf("\n\t\t                >>> 2-按手機號碼排序               ");
  748.            printf("\n\t\t                >>> 3-返回主菜單                   ");
  749.        printf("                 請輸入您的數字選擇:    ");
  750. loop10:                scanf("%d",&i);
  751.            switch(i)
  752.            {
  753.                  case 1:listbyname();break;
  754.                  case 2:listbycelephone();break;
  755.                  case 3:mainmenu();break;
  756.                  default:printf("對不起!您的輸入有誤!請重新輸入:   ");goto loop10;
  757.            }
  758.         }
  759. }


  760. void listbyname()//*按姓名排序*//
  761. {
  762.         int i,j,k;
  763.         struct person tmp;
  764.         for (i=1;i<num;i++)
  765.         {
  766.                 if(strcmp(communication[i].name,communication[i-1].name)<0)
  767.                 {
  768.                         tmp=communication[i];
  769.                         j=i-1;
  770.                         do
  771.                         {
  772.                                 communication[j+1]=communication[j];
  773.                                 j--;
  774.                         }
  775.                         while ((strcmp(tmp.name,communication[j].name)<0&&j>=0));
  776.                         communication[j+1]=tmp;
  777.                 }
  778.         }
  779.             printf("\n\t\t排序成功,是否顯示?(1代表繼續;2代表不繼續)");
  780.                 printf("          請輸入您的數字選擇:    ");
  781.                 scanf("%d",&k);
  782.                 if (k==1)   
  783.                    showall();
  784.             return;
  785. }


  786. void listbycelephone()//*按手機號碼排序*//
  787. {
  788.         int i,j,k;
  789.         struct person tmp;
  790.         for (i=1;i<num;i++)
  791.         {
  792.                 if(strcmp(communication[i].celephone,communication[i-1].celephone)<0)
  793.                 {
  794.                         tmp=communication[i];
  795.                         j=i-1;
  796.                         do
  797.                         {
  798.                                 communication[j+1]=communication[j];
  799.                                 j--;
  800.                         }while ((strcmp(tmp.celephone,communication[j].celephone)<0)&&j>=0);
  801.                         communication[j+1]=tmp;
  802.                 }
  803.         }
  804.         printf("\n\t\t排序成功,是否顯示?(1代表繼續;2代表不繼續)");
  805.         printf("          請輸入您的數字選擇:    ");
  806.         scanf("%d",&k);
  807.         if (k==1)
  808.            showall();
  809.         return;
  810. }








  811. void showall()//*輸 出 全 部 信 息*//
  812. {
  813.         int i,j;
  814.         system("cls");
  815.         system("color 3b");
  816.         if(num!=0)
  817.         {
  818.                 printf("\n\t\t*************** 以下為通訊錄所有信息************");
  819.                 for (i=0;i<num;i++)
  820.                 {
  821.                         printf("\n\t\t________________________________");
  822.                         printf("\n\t\t   名字:    %s",communication[i].name);
  823.                         printf("\n\t\t   類別:    %s",communication[i].type);
  824.                         printf("\n\t\t   年齡:    %d",communication[i].nianling);
  825.                         printf("\n\t\t   郵編:    %ld",communication[i].youbian);
  826.                         printf("\n\t\t   地址:    %s",communication[i].addr);
  827.                         printf("\n\t\t   手機號碼:%s",communication[i].celephone);
  828.                         printf("\n\t\t   固定電話:%s",communication[i].homephone);
  829.                         printf("\n\t\t   公司名稱:%s",communication[i].company);
  830.                         printf("\n\t\t   電子郵件:%s",communication[i].email);
  831.                         printf("\n\t\t   QQ號碼:  %s",communication[i].QQ);
  832.                         printf("\n\t\t________________________________");
  833.                         printf("\t\t");
  834.                         if (i+1<num)
  835.                         {
  836.                                 printf("\n\t\t__________________________");
  837.                                 system("pause");
  838.                         }
  839.                 }         
  840.                 printf("\n\t\t************************************************");
  841.         }
  842.         else
  843.            printf("\n\t\t對不起!通訊錄中無任何紀錄!");
  844.         printf("\n\t\t請按任意數字鍵返回主菜單");
  845.         scanf("%d",&j);
  846.         return;  
  847. }




  848. void writetofile()//*寫入文件*//
  849. {
  850.         int i,k;
  851.         system("cls");
  852.         system("color 84");
  853.         if ((fp=fopen("communication.txt","wb"))==NULL)
  854.         {
  855.                 printf("\n\t\t文件打開失敗");
  856.         }
  857.         for (i=0;i<num;i++)
  858.         {
  859.                 if (fwrite(&communication[i],sizeof(struct person),1,fp)!=1)
  860.                 {
  861.                         printf("\n\t\t寫入文件錯誤!\n");
  862.                 }
  863.         }
  864.         fclose(fp);
  865.         printf("\n\t\t通訊錄文件已保存");
  866.         printf("\n\t\t請按任意數字鍵返回主菜單");
  867.         scanf("%d",&k);
  868.         return;
  869. }







  870. void readfromfile()//*讀取文件*//
  871. {
  872.     int i,j,k;
  873.     system("cls");
  874.         system("color 2b");
  875.         if((fp=fopen("communication.txt","rb"))==NULL)
  876.         {
  877.                 printf("\n\t\t        ****************************");
  878.                 printf("\n\t\t        *                          *");
  879.                 printf("\n\t\t        *                          *");
  880.                 printf("\n\t\t        *     通訊錄文件不存在     *");
  881.                 if ((fp=fopen("communication.txt","wb"))==NULL)
  882.                 {
  883.                         printf("\n        *         建立失敗         *");
  884.                         printf("\n        *                          *");
  885.                         printf("\n        *                          *");
  886.                         printf("\n        ****************************");
  887.                         exit(0);
  888.                 }
  889.                 else
  890.                 {
  891.                         printf("\n\t\t        *     通訊錄文件已建立     *");
  892.                         printf("\n\t\t        *                          *");
  893.                         printf("\n\t\t        *                          *");
  894.                         printf("\n\t\t        ****************************");
  895.                         printf("\n\t\t          >>> 進入主菜單    ");
  896.                         printf("\n\t\t          >>> 請輸入任意數字并回車:    ");
  897.                     scanf("%d",&k);
  898.                         return;               
  899.                 }
  900.                 exit(0);
  901.         }
  902.         fseek(fp,0,2); //*文件位置指針移動到文件末尾*//
  903.         if (ftell(fp)>0) //*文件不為空*//
  904.         {
  905.                 rewind(fp); //*文件位置指針移動到文件開始位置*//
  906.                 for (num=0;!feof(fp) && fread(&communication[num],sizeof(struct person),1,fp);num++);
  907.                 printf("\n\t\t        ****************************");
  908.                 printf("\n\t\t        *                          *");
  909.                 printf("\n\t\t        *                          *");
  910.                 printf("\n\t\t        *     文件導入成功!        *");  
  911.                 printf("\n\t\t        *                          *");
  912.                 printf("\n\t\t        *                          *");
  913.                 printf("\n\t\t        ****************************");
  914.                 printf("\n\t\t        >>> 按1顯示所有信息,按2回主菜單!     ");
  915.                 printf("\t\t          >>> 請輸入您的數字選擇:    ");
  916.                 scanf("%d",&j);
  917.                 if(j==1)
  918.                   showall();
  919.         }
  920. else
  921. {
  922.         printf("\n\t\t        ****************************");
  923.         printf("\n\t\t        *                          *");
  924.         printf("\n\t\t        *                          *");
  925.         printf("\n\t\t        *     文件導入成功!        *");
  926.         printf("\n\t\t        *  通訊錄文件中無任何紀錄! *");
  927.         printf("\n\t\t        *                          *");
  928.         printf("\n\t\t        *                          *");
  929.         printf("\n\t\t         ****************************");
  930.         printf("\n\t\t       >>> 請按任意數字鍵返回主菜單");
  931.         scanf("%d",&i);
  932.         return;
  933. }
  934. }



  935. void deleteall()//*刪除所有信息*//
  936. {
  937.     int i,j;
  938.         system("cls");
  939.         system("color 50");
  940.         printf("\n\t\t確認刪除?\n");
  941.         printf("請按1和2(1代表確認;2代表不刪除)\n ");
  942.         scanf("%d",&i);
  943.         if (i==1)
  944.         {
  945.                 fclose(fp);
  946.                 if ((fp=fopen("communication.txt","wb"))==NULL)
  947.              {
  948.                     printf("\n\t\t不能打開文件,刪除失敗");
  949.                     readfromfile();
  950.              }
  951.             num=0;
  952.             printf("\n\t\t紀錄已刪除!");
  953.             printf("\n\t\t請按任意數字鍵返回主菜單");
  954.             scanf("%d",&j);
  955.             return;
  956.         }

  957. }

復制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 一级女毛片 | 激情一区二区三区 | 成人免费看 | 国产美女免费视频 | 成人在线精品 | 亚洲成人三级 | 国产精品免费一区二区三区四区 | 福利社午夜影院 | 人人爽日日躁夜夜躁尤物 | 色综合99| 91原创视频在线观看 | 国产精品久久一区二区三区 | 国产一区二区在线91 | 五月婷亚洲 | 欧美成人猛片aaaaaaa | 在线观看中文字幕视频 | 欧美精品一区二区三区四区五区 | 日韩久久中文字幕 | 成人 在线| 99热在线免费 | 国产伊人精品 | 一区二区播放 | 国产精品久久久久久亚洲调教 | 欧美精品在线一区二区三区 | 国产1区2区 | 97国产爽爽爽久久久 | 欧美日韩高清 | 日本小视频网站 | 国产三级日本三级 | 成人在线观看免费 | 亚洲高清视频在线观看 | 国产精品久久久久久久久久久新郎 | a毛片| 国产成人免费 | 国产一卡二卡三卡 | 久久久人成影片一区二区三区 | 欧美一区视频在线 | 国产综合视频 | 成人在线视频免费观看 | 成人国产精品久久 | 精品三级在线观看 |