Linked Questions

Popular Questions

Best way to switch on a string in C

Asked by At

In C there is a switch construct, which enables one to execute different conditional branches of code based on an test integer value, e.g.,

int a;
/* Read the value of "a" from some source, e.g. user input */
switch ( a ) {
case 100:
  // Code
case 200:
  // Code
  // Code

How is it possible to obtain the same behavior (i.e. avoid the so-called "if-else ladder") for a string value, i.e., a char *?

Related Questions