Advertisement
KuoHsiangYu

英文字母小寫轉大寫.c

Aug 5th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. //郭翔宇
  2. //英文字母小寫轉大寫
  3. #define _CRT_SECURE_NO_WARNINGS
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10.     system("color f0");
  11.  
  12.     char input[51] = {};
  13.     char output[51] = {};
  14.     printf("請輸入英文字母:");
  15.     scanf("%50s", &input);
  16.     printf("input = %s\n", input);
  17.     int i = 0;
  18.     for (i = 0; input[i] != '\0'; i++)
  19.     {
  20.         if (input[i] >= 'a' && input[i] <= 'z')
  21.         {
  22.             output[i] = input[i] - ('a' - 'A');
  23.         }
  24.         else
  25.         {
  26.             output[i] = input[i];
  27.         }
  28.     }
  29.     printf("output = %s\n", output);
  30.  
  31.     printf("\n");
  32.     system("pause");
  33.     return 0;
  34. }
  35.  
  36. /*
  37. 【程式執行結果】
  38. 請輸入英文字母:abcd efgh
  39. nput = abcd
  40. utput = ABCD
  41.  
  42. 請按任意鍵繼續 . . .
  43. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement