1

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.

  • 1
    There's no meaningful way you could make `char[]`/`char*` work with a switch statement. You would need to be able to provide compile time constants for the case statements to compare for equality, and you won't be able to provide that. – Jeff Mercado Oct 31 '19 at 05:59

1 Answers1

1

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).

DarkAtom
  • 2,589
  • 1
  • 11
  • 27