0

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!

5
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by miskeen
1

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

0

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

0

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 by gerard4143: n/a

-1

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

you can also use function pointers to do same thing.

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.