Hey everoyne. I'm wondering If it's possible to construct a switch statement which takes in a character and determines weither that character is a number or not, or an alphabetical number.

switch(i) /*character*/ {
    case '0': /*ok it's a number, doesn't have to be zero, any number from 0-9*/
    case 'a': /*ok it's an alphabetical number, doesn't have to be a but any from a-z*/
} 

Or do I have to write for each case , like so

switch(i) {
    case '0': break;
    case '1': break;
    ....
    ....
    ....
    case '9': break;
    case 'a': break;
    ....
    ....
    .... 'z': break;
}

I feel like I've seen a lighter version of switch statment where they used tricks like this??

Recommended Answers

You could do that, but there is a much easier way if you use the macros in ctype.h

if( isdigit(i) )
{
    // blabla
} else if( isalpha(i) )
{
   // blabla
 }
Jump to Post

All 2 Replies

You could do that, but there is a much easier way if you use the macros in ctype.h

if( isdigit(i) )
{
    // blabla
} else if( isalpha(i) )
{
   // blabla
 }

Of course, thank you ancient dragon :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.