monoteen

CK_C++_Chapter9

Jun 7th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #pragma warning (disable:4996)
  4.  
  5. struct login_info
  6. {
  7.     char id[20];
  8.     char passwd[20];
  9. };
  10.  
  11. typedef struct login_info LOGIN_INFO;
  12.  
  13. LOGIN_INFO arr[100];
  14. int num = 0;
  15.  
  16. int main(void)
  17. {
  18.     char id[20], passwd[20];
  19.     int i;
  20.     int found;
  21.  
  22.     while (1)
  23.     {
  24.         printf("ID: ");
  25.         gets(id);
  26.  
  27.         if (strcmp(id, ".") == 0)
  28.             break;
  29.  
  30.         found = -1;
  31.         for (i = 0; i < num; i++)
  32.         {
  33.             if (strcmp(id, arr[i].id) == 0)
  34.             {
  35.                 found = i;
  36.                 break;
  37.             }
  38.         }
  39.         if (found == -1)
  40.         {
  41.             char yesno;
  42.             printf("등록 되지 않은 ID입니다. 회원가입을 하시겠습니까? (Y/N) : ");
  43.             scanf("%c", &yesno);
  44.             fflush(stdin);
  45.  
  46.             if (yesno == 'y' || yesno == 'Y')
  47.             {
  48.                 printf("ID를 입력하세요 : ");
  49.                 gets(arr[num].id);
  50.                 printf("패스워드를 입력하세요 : ");
  51.                 gets(arr[num].passwd);
  52.                 num++;
  53.             }
  54.             else
  55.                 continue;
  56.         }
  57.         else
  58.         {
  59.             printf("PASSWORD : ");
  60.             gets(passwd);
  61.  
  62.             if (strcmp(passwd, arr[found].passwd) == 0)
  63.                 printf("로그인 되었습니다.\n");
  64.             else
  65.                 printf("패스워드가 틀립니다.\n");
  66.         }
  67.     }
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment