How can I use switch case with array in C? I know I can use if statement to fulfill my need like:
char *choice[]={'option1', 'option2'}
if (strcmp choice[0], input)==0){
// do the job
}
else{
// something
}
So the reason I wrote this is because I have seen people giving some good guides here but its not what the person asked for so just wanted to clarify that I know the concepts its just I to get the hints or relevant example to see how i can use switch case with array in C language. There are some places which says switch cannot use array strings so want to clarify if thats true.
switch(expression)if and only if expression have integer type. Since a C style string doesn't have integer type, you can't do aswitchon strings. There is no workaround, i.e. usestrcmpfor comparing stringschar *choice[]={'option1', 'option2'}is wrong. Use"instead of'