0

Write program in "c" where i can identify a lower or upper case letter taken from the user and turn them into opposite case!

https://code.sololearn.com/c45BDX0jFjJu/?ref=app https://code.sololearn.com/c45BDX0jFjJu/?ref=app

19th Feb 2022, 7:03 AM
ANIK
ANIK - avatar
6 ответов
0
https://code.sololearn.com/cv269Zq5zpXq/?ref=app
19th Feb 2022, 8:12 AM
HungryTradie
HungryTradie - avatar
+ 2
The following might be a little beyond your current studies, but here is a way to toggle between upper/lowercase without checking which one it is at first. Understand that the difference between upper- and lowercase is 32. Recognize that 32 is a single bit (bit5). The bitwise exclusive-or operator (^) is useful to flip a bit to its opposite value. It can change 0 to 1, or 1 to 0 automatically. Here is a sample of how to do it: #include <ctype.h> //for isalpha() . . . char ch; scanf("%c", &ch); if (isalpha(ch)) ch ^= 32; //toggle case printf("%c", ch);
19th Feb 2022, 3:25 PM
Brian
Brian - avatar
+ 1
Wow,that was so insightful i am actually new at this,just came to my mind,thank you for your time! appreciate it
19th Feb 2022, 8:17 AM
ANIK
ANIK - avatar
+ 1
That is very cool Brian I might now do some research on how the ASCii values were originally decided, seems likely that +32 was not an accident. I guess 64+1 for A was also not an accident.
19th Feb 2022, 11:05 PM
HungryTradie
HungryTradie - avatar
0
#include<cytpe.h> tolower(char) toupper(char)
19th Feb 2022, 7:26 AM
Raul Ramirez
Raul Ramirez - avatar
0
You are coding in C, so you are gunna like to do it the hard way🙃 Do you know (or will you google) the ASCii numbers for lowercase and uppercase? Could you check each character of the string is >=97 && <=122
19th Feb 2022, 7:57 AM
HungryTradie
HungryTradie - avatar