In article <80**********************************@t1g2000pra.g ooglegroups.com>,
asit <li*****@gmail.comwrote:
>please modify to get the correct output.(switch case is compulsory)
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character : ");
ch=getch();
You haven't shown us the definition of getch(). (I assume it's not
entirely unlike getchar()?)
switch(ch)
{
case (ch>=65 && ch<=90):
printf("Capital Letter\n");
break;
case (ch>=97 && ch<=122):
printf("Small Case Letter\n");
break;
case (ch>=48 && ch<=57):
printf("Digit\n");
break;
default:
printf("Any other character");
}
return 0;
}
Case arguments need to be constant expressions.
The Right Way to do range checks is to not use a switch (and The Right
Way to identify digits and case of letters isn't to use range checks),
but if the switch is non-negotiable:
--------
#include <ctype.h>
#include <stdio.h>
/*Not compiled or tested. Caveat emptor.*/
int main(void)
{
char ch;
printf("Enter any character: "); fflush(stdout);
ch=getchar();
switch(isupper(ch))
{
case 0:
switch(islower(ch))
{
case 0:
switch(isdigit(ch))
{
case 0:
printf("Other character\n");
break;
default:
printf("Digit\n");
break;
}
break;
default:
printf("Lower-case letter\n");
break;
}
break;
default:
printf("Upper-case letter\n");
break;
}
return 0;
}
--------
dave
--
Dave Vandervies dj3vande at eskimo dot com
[T]he only real 'crippled environment' I have a problem with is my own mind.
--Gary S. Callison in the scary devil monastery