About 447,000 results
Open links in new tab
  1. How can I compare strings in C using a `switch` statement?

    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 …

  2. How can I use ranges in a switch case statement in C?

    Apr 20, 2016 · In the C programming language the case statement used in a switch() statement must specify a value that the compiler can turn into a constant in some way. Each of the …

  3. C# how to use enum with switch - Stack Overflow

    Feb 28, 2013 · Switch case enables you to reuse the same code block for multiple cases. If you do - make sure to not use brackets.

  4. C - Switch with multiple case numbers - Stack Overflow

    switch (x){ case 1: case 2: case 3: case 4: case 5: case 6: printf ("The number you entered is >= 1 and <= 6\n"); break; } Edit: Using something to the effect of switch (x / 10) is another good way …

  5. c - How to write switch statement with "or" logic? - Stack Overflow

    Mar 10, 2013 · Below, I have created a simple switch statement that works fine. I was wondering how I could change this code so it is switch (c), then case 1, case 2, case 3, default.

  6. c - When to use 'if' vs 'switch' statements? - Stack Overflow

    Oct 28, 2016 · 1 Without getting me lost in complex issues, will there be scenarios where switch cases will not work later on in complex programming? In theory, you can frame any if-else …

  7. Larger than and less than in C switch statement - Stack Overflow

    In your problem definition it is not mentioned to use only switch case. if else is way to go!

  8. C Switch-case curly braces after every case - Stack Overflow

    May 29, 2015 · In a C switch-case flow control, it's required to put curly braces { } after a case if variables are being defined in that block. Is it bad practice to put curly braces after every case, …

  9. c - Switch statement with strings? - Stack Overflow

    switch (choice[0]) { case 'f': // they chose fish break; case 'c': // they chose chips break; case 'd': // they chose drink } This will be faster than using (although it doesn't matter for your case) and …

  10. Why can't the switch statement be applied to strings?

    The reason why has to do with the type system. C/C++ doesn't really support strings as a type. It does support the idea of a constant char array but it doesn't really fully understand the notion …