Hello guys,

How can I make a switch case using an array of chars.
Ex:

char input[50];
// my code here
switch ( input ) {
        case "abc":  
            // do something
            break;
        case "xyz":          
            // do otherthings
            break;
}

Is that possible in C?

Thank you!

The controlling expression of a switch shall have integer type.
An array of chars will not do.

But, is there any proposed solution to what I'm looking for?

But, is there any proposed solution to what I'm looking for?

Your comparing a array of characters(char input[50]) that is supposed to be a C style string("abc")...I would investigate string compare functions

Edited 7 Years Ago by gerard4143: n/a

But, is there any proposed solution to what I'm looking for?

you can also use function pointers to do same thing.

But, is there any proposed solution to what I'm looking for?

use if() statement and strcmp() function for your purpose.

This question has already been answered. Start a new discussion instead.