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

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.

Thank you! I'm going to use strcmp.

Be a part of the DaniWeb community

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