MUstar

IoT C언어 0615 - 주소록프로그램v1

Jun 18th, 2017
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. //-----------------------------함수원형선언
  6. int menu(void);
  7. int addt(void);
  8. int edit(void);
  9. int dele(void);
  10. int view(void);
  11. int pause(int err);
  12. int end(void);
  13. //-----------------------------공동사용함수
  14. char name[300], birth[600], telnum[1100];
  15. int count = 0, ckdel=0 ;
  16. //-----------------------------유저정보저장
  17. struct telbook{
  18.     char name[20];
  19.     int birth;
  20.     char telnum[20];
  21. //  char email[100];
  22. //  char works[20];
  23. };
  24. struct telbook table[100];
  25. //----------------------------------------
  26.  
  27. //프로그램 메인
  28. int main(void){
  29.     menu();
  30.     end();
  31. }
  32.  
  33. int menu(void){
  34.     while(1){
  35.         int sele;
  36.         system("clear");
  37.         printf("간단한주소록프로그램\n");
  38.         printf("1)추가 2)항목수정 3)삭제 4)조회 5)종료 \n");
  39.         printf(">");scanf("%d", &sele);
  40.        
  41.         if(sele==1) addt();
  42.         else if (sele==2) edit();
  43.         else if (sele==3) dele();
  44.         else if (sele==4) view();
  45.         else if (sele==5) break;
  46.         else pause(1);
  47.     }
  48. }
  49.  
  50. int view(void){
  51.     int cnt=0;
  52.         system("clear");
  53.         if(count==0)
  54.     {
  55.         printf("목록이 비어 있습니다. 추가해주세요.\n");
  56.         pause(0);
  57.     }
  58.     else{
  59.         printf("번호/이름/나이/생년월일/폰번호\n");
  60.         printf("Ex>0|최나나|19981212|20세|01012341234\n");
  61.         printf("--------------------------------------------------------\n");
  62.         while(cnt<count){
  63.         int age = 2017- table[cnt].birth/10000 +1;
  64.         if(cnt<=8) printf("00%d|",cnt+1);
  65.         else if(cnt<=98) printf("0%d|",cnt+1);
  66.         else printf("%d|",cnt+1);
  67.         printf("%s|%d세|%d|%s\n",table[cnt].name,age,table[cnt].birth,table[cnt].telnum);
  68.         printf("--------------------------------------------------------\n");
  69.         cnt++;
  70.         }
  71.         pause(0);
  72.     }
  73. }
  74.  
  75. int addt(void){
  76.     system("clear");
  77.     while(2){
  78.         if(count==100){printf("현재 등록된 연락처가 100개입니다.\n더이상 등록이 불가능합니다.\n"); break;}
  79.         printf("주소록에 연락처을 추가하실라면 입력하세요.\n");
  80.         printf("현재 %d개 등록이 가능합니다.\n", 100-count);
  81.         printf("구분은 스페이스바 또는 엔터로 구분합니다.\n");
  82.         printf("이름/생년월일/전화번호\n");
  83.         printf("예>최나나 19981212 01012341234\n");
  84.         printf(">");scanf("%s%d%s", table[count].name,&table[count].birth,table[count].telnum);
  85.         printf("값이 저장되었습니다.\n");
  86.         ckdel=0;
  87.         count++;
  88.         break;
  89.         }
  90.     pause(0);
  91. }
  92.  
  93. int dele(void){
  94.     int del_cnt;
  95.     system("clear");
  96.     while(del_cnt<count){
  97.         strcpy(table[del_cnt].name, "dummy");
  98.         table[del_cnt].birth = 0x00;
  99.         strcpy(table[del_cnt].telnum, "dummy");
  100.         del_cnt++;
  101.     }
  102.     count = 0;
  103.     printf("입력된 값들이 삭제되었습니다.\n");
  104.     ckdel=1;
  105.     pause(0);
  106. }
  107.  
  108. int edit(void){
  109.     int table_num, sel2,search_cnt=0;
  110.     char search[20];
  111.     while(3){
  112.         while(4){
  113.             system("clear");
  114.             printf("사람이름입력>");
  115.             scanf("%s", search);
  116.             while(5){
  117.                 if(strcmp(table[search_cnt].name, search)==0){table_num = search_cnt; break;}
  118.                 if(search_cnt == 100){pause(2); search_cnt = 0; break;}
  119.                 search_cnt++;
  120.             }
  121.             strcpy(search,"dummy");
  122.             if(search_cnt == table_num) break;
  123.         }
  124.         printf("멀 수정할래?\n");
  125.         printf("1)생일 2)폰번호\n");
  126.         printf(">");scanf("%d", &sel2);
  127.         if((sel2<=0)||(sel2>=5))pause(1);
  128.         else if(sel2==1){printf("바꿀값입력>");scanf("%d",&table[search_cnt].birth);}
  129.         else if(sel2==2){printf("바꿀값입력>");scanf("%s",table[search_cnt].telnum);}
  130.         //else if(sel2==3){printf("바꿀값입력>");scanf("%s",table[search_cnt].email);}
  131.         //else if(sel2==4){printf("바꿀값입력>");scanf("%s",table[search_cnt].works);}
  132.         else pause(1);
  133.         break;
  134.     }
  135.     printf("완료되었습니다.\n");
  136.     pause(0);
  137. }
  138.  
  139. int pause(int err){
  140.     char p_dummy[100];
  141.     if(err==1){system("clear"); printf("잘못된 값을 입력했습니다.");}
  142.     if(err==2){system("clear"); printf("같은값을 찾을수가 없습니다.");}
  143.     printf("\n-------");
  144.     printf("\n계속하실려면 아무글자나 입력후 엔터를 눌려주세요.\n");
  145.     scanf("%s", p_dummy);
  146.     strcpy(p_dummy, " ");
  147. }
  148.  
  149. int end(void){
  150.     system("clear");
  151.     printf("프로그램을 종료합니다.\n");
  152.     return 0;
  153. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×