How can I give condition in my program for a character to be a Capital letter? Without using ASCII values | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I give condition in my program for a character to be a Capital letter? Without using ASCII values

18th Feb 2018, 11:02 AM
Sufal Chhabra
Sufal Chhabra - avatar
12 Answers
+ 4
Assuming c is a char containing a letter, if (c < 'a') // it's uppercase else // it's lowercase Not really sure what you mean by not using ASCII values though...
18th Feb 2018, 12:29 PM
deFault
+ 11
Which language?
18th Feb 2018, 11:08 AM
jay
jay - avatar
+ 6
As an alternative you can also use isalpha() function, which returns 1 for uppercase, 2 for lowercase, or zero if the character is non alphabetical. int cc = isalpha(chr); switch(cc) { case 1: printf("Uppercase"); break; case 2: printf("Lowercase"); break; default: printf("Non alphabetical"); }
18th Feb 2018, 6:45 PM
Ipang
+ 5
Oh, so don't use hardcoded ASCII values in numeric form. I had doubts about the meaning of that because, technically char literal 'a' is the same as 97 or 0x61, and in the if statement ASCII value of c is compered with the literal be it 'a', 97 or 0x61. Anyway, you can always use char literals instead of the numeric values. Like in: if (c >= '0' && c <= '9') // it's a digit else if (c >= 'a' && c <= 'z') // it's lowercase letter else if (c >= 'A' && c <= 'Z') // it's uppercase letter // and so on...
18th Feb 2018, 12:48 PM
deFault
18th Feb 2018, 1:25 PM
JaatPTM("Paritosh Malik");
JaatPTM("Paritosh Malik"); - avatar
+ 3
in java to check if character is caps use syntax - Character.is UpperCase() to change into caps use - Charactet.ToUpperCase()
18th Feb 2018, 3:04 PM
K. M. Tyagi
K. M. Tyagi - avatar
+ 1
in C
18th Feb 2018, 11:09 AM
Sufal Chhabra
Sufal Chhabra - avatar
+ 1
i meant that don't use the ASCII value of characters like a=97,A=65
18th Feb 2018, 12:37 PM
Sufal Chhabra
Sufal Chhabra - avatar
+ 1
thaks Ipang for this alternative
19th Feb 2018, 1:59 AM
Sufal Chhabra
Sufal Chhabra - avatar
0
print 1 if entered letter is capital and zero if entered letter is small
18th Feb 2018, 11:13 AM
Sufal Chhabra
Sufal Chhabra - avatar
0
thanks marvin
18th Feb 2018, 12:35 PM
Sufal Chhabra
Sufal Chhabra - avatar
0
JaatPTM thanks bro it is a good code
18th Feb 2018, 3:27 PM
Sufal Chhabra
Sufal Chhabra - avatar