Reputation: 35
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' "
Upvotes: 0
Views: 611
Reputation: 103
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/toggle-case-string-using-bitwise-operators/
Upvotes: 1
Reputation: 26800
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.
Upvotes: 2