0

How do I change a lower case char to an upper chase char without having to use functions like isdigit, isupper, toupper, isalnum, isalpha, or without having to add or subtract the number 32. Also I am supposed to use it in the while loop.

For example: If I type the letter b into the .exe, it should send me a message that says "Remember that proper nouns starts with capital and you should've typed 'B' "

enter image description here

user4581301
  • 33,082
  • 7
  • 33
  • 54
LLC
  • 35
  • 2
  • `if (b) return B` – kmdreko Feb 27 '19 at 05:09
  • Is there a way I can do this with all the characters included? Instead of having to do it one by one? – LLC Feb 27 '19 at 05:34
  • 2
    Possible duplicate of [Lower case to upper case without toupper](https://stackoverflow.com/questions/25063998/lower-case-to-upper-case-without-toupper) – phuclv Feb 27 '19 at 06:05

2 Answers2

2

If your platform has ASCII character set, then you can use XOR to achieve this.

char c = 'a';
c ^= 32; // c will now contain 'A'

This is possible because of the way ASCII values have been chosen. The difference between the decimal values of small and capital letters of the English alphabet is exactly 32.

If your platform has EBCDIC character set, then you can do

char c = 'a';
c ^= 64; // c will now contain 'A'

It works because of the same reason mentioned above, only this time the difference is 64 instead of 32.

P.W
  • 26,289
  • 6
  • 39
  • 76
1

You might use this

 char c = 'A' (to lower case )
 c = c | 32   (TRY THIS..)
 c &= ~32     (as suggested by jejo) 

https://www.geeksforgeeks.org/case-conversion-lower-upper-vice-versa-string-using-bitwise-operators-cc/

https://www.geeksforgeeks.org/toggle-case-string-using-bitwise-operators/

sha111
  • 113
  • 1
  • 12
  • You should mention that this works for characters encoded ASCII, which is quite common, but it is not a general solution. – Pete Becker Feb 27 '19 at 15:50