+ 1
How can I give condition in my program for a character to be a Capital letter? Without using ASCII values
12 odpowiedzi
+ 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...
+ 11
Which language?
+ 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");
}
+ 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...
+ 3
in java
to check if character is caps use syntax - Character.is UpperCase()
to change into caps use - Charactet.ToUpperCase()
+ 1
in C
+ 1
i meant that don't use the ASCII value of characters
like a=97,A=65
+ 1
thaks Ipang for this alternative
0
print 1 if entered letter is capital and zero if entered letter is small
0
thanks marvin
0
JaatPTM thanks bro
it is a good code