MUstar

IoT C언어 0710 - EX15_1

Jul 15th, 2017
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. char input_name(char (*name)[20]);
  5. void print_name(char (*name)[20],int cnt);
  6.  
  7. int main(void)
  8. {
  9.     char name[10][20];
  10.     int cnt;
  11.  
  12.     cnt = input_name(name);
  13.     print_name(name,cnt);
  14.  
  15.     return 0;
  16. }
  17.  
  18. char input_name(char (*name)[20])
  19. {
  20.     static int cnt=0;
  21.     int cksum=0;
  22.     while(1)
  23.     {
  24.         char temp[20];
  25.         printf("이름 : ");
  26.         scanf("%s",temp);
  27.         if(strcmp(temp,"end")==0) break;
  28.         for(int i=0;i<cnt;i++)
  29.             if(strcmp(name[i],temp)==0) cksum++;
  30.         if(cksum>0)
  31.         {
  32.             printf("# 이름이 이미 등록되어있습니다!\n");
  33.             cksum=0;
  34.         }
  35.         else
  36.         {
  37.             strcpy(name[cnt],temp);
  38.             cnt++;
  39.         }
  40.     }
  41.     printf("# 총 %d명이 입력되었습니다.\n",cnt);
  42.  
  43.     return cnt;
  44. }
  45.  
  46. void print_name(char (*name)[20],int cnt)
  47. {
  48.     for(int i=0;i<cnt;i++)
  49.         printf("%s\n",name[i]);
  50. }
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.

×