Advertisement
userxbw

Print ascii magic number upper to lower case

Aug 19th, 2022 (edited)
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. /* ascii letters is a range of
  5.    numbers within a total amount
  6.    of numbers.
  7.    lowercase 97-122 a-z
  8.    uppercase 65-90 A-Z
  9.    to make a lowercase to
  10.    an uppercase -32 to
  11.    the value of the lowercase
  12.    to make uppercase to
  13.    lowercase +32 to
  14.    the value of the uppercase */
  15.  
  16. char a,b;
  17.  printf("enter a letter,\n"
  18.         "Upper or Lower case\n");
  19.  
  20.   scanf(" %c",&a);
  21. /* this is assuming an
  22.   actual letter is being
  23.   inputted. */
  24.  if(a >= 65 && a <= 90)
  25.      printf("\nchanged to \n"
  26.      "lowercase %c \n", a+=32);
  27.   else
  28.    printf("wrong input %c\n",a);
  29.  
  30.  if(a >= 97 && a <= 122)
  31.     printf("\nchanged to\n"
  32.            "uppercase %c\n",a-=32);
  33.   else
  34.    printf("wrong input %c\n",a);
  35.  
  36.  
  37. printf("using a switch to "
  38.         "switch it back\n");
  39.     switch(a){
  40.        case 65 ... 90:
  41.           printf("\nchanged to \n"
  42.           "lowercase %c \n", a^=32);
  43.           break;
  44.         case 97 ... 122:
  45.           printf("\nchanged to\n"
  46.           "uppercase %c\n",a^=32);
  47.           break;
  48.          default:
  49.            printf("\nwrong input %c\n",a);
  50.      }
  51.  
  52.  
  53. /*
  54.  
  55. getting the value between the letters
  56. regardless of what they are.
  57.  
  58. using the above:
  59. Lower case letter (minus) upper case letter.
  60.  
  61. So it's get the integer values of each
  62. letter. The lower case is the higher
  63. numbers in the ASCII Table so subtract
  64. the upper case value with the lower case
  65. value to get the difference.
  66.  
  67. Input lower case letter
  68.  
  69. g = 103
  70.  
  71. input upper case letter
  72.  
  73. B = 66
  74.  
  75. Different is g minus B or
  76. X=103-66
  77.  
  78. char is an integer so you can easily get
  79. the number of the letter by simply changing
  80. the data type.
  81.  
  82. char d='h';
  83. int f = (int)d;
  84. printf("%d %c",f,f);
  85.  
  86. 104 h
  87. */
  88. printf("the difference between 2 "
  89. "letters\nenter an lower case letter\n");
  90. scanf(" %c",&a);
  91. printf("\nenter an upper letter\n");
  92. scanf(" %c",&b);
  93.  
  94. /*   lowercase 97-122 a-z
  95.      uppercase 65-90 A-Z */
  96.  
  97.  if (a >= 97 && a <= 122 &&
  98.      b >= 65 && b <= 90)
  99.  
  100. /*  put everything in one printf */
  101. printf("the ascii integer value "
  102.        "difference between the two"
  103.        " are\n%c - %c\n%d - %d\n"
  104.        "= %d\n",a,b,a,b,(int)a-(int)b);
  105. else
  106.   printf("you failed to follow instructions\n"
  107.          "%c :: %c\n",a,b);
  108.  return 0;
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement