Advertisement
userxbw

ASCII TABLE manipulation magic number is 32

Aug 19th, 2022 (edited)
724
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.  
  5.  
  6. /* ascii letters is a range of
  7.    numbers within a total amount
  8.    of numbers.
  9.    lowercase 97-122 a-z
  10.    uppercase 65-90 A-Z
  11.    to make a lowercase to
  12.    an uppercase -32 to
  13.    the value of the lowercase
  14.    to make uppercase to
  15.    lowercase +32 to
  16.    the value of the uppercase */
  17.  
  18. char a,b;
  19.  printf("enter a letter,\n"
  20.         "Upper or Lower case\n");
  21.  
  22.   scanf(" %c",&a);
  23. /* this is assuming an
  24.   actual letter is being
  25.   inputted. */
  26.  if(a >= 65 && a <= 90)
  27.      printf("\nchanged to \n"
  28.      "lowercase %c \n", a+=32);
  29.   else
  30.    printf("wrong input %c\n",a);
  31.  if(a >= 97 && a <= 122)
  32.     printf("\nchanged to\n"
  33.            "uppercase %c\n",a-=32);
  34.   else
  35.    printf("wrong input %c\n",a);
  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