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
6 Respuestas
0
https://code.sololearn.com/cv269Zq5zpXq/?ref=app
+ 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);
+ 1
Wow,that was so insightful
i am actually new at this,just came to my mind,thank you for your time! appreciate it
+ 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.
0
#include<cytpe.h>
tolower(char)
toupper(char)
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