I hope that you already know that switch
keyword only accepts int
or char
. but is there a way so that it would also accept char *
?
I have an Idea how to solve this by using struct, but I'm gonna wait for your opinion.
I hope that you already know that switch
keyword only accepts int
or char
. but is there a way so that it would also accept char *
?
I have an Idea how to solve this by using struct, but I'm gonna wait for your opinion.
Sadly, no, you cannot have string literals in switch
statements. This is because switching a char*
would mean the cases need to be memory addresses (after all, char*
is still just a pointer).