da_Aresinger

Excuse Me What The Heck?

May 11th, 2022
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. // inspired by this StackOverflow page:
  2. // https://stackoverflow.com/questions/8202199/is-it-possible-to-use-goto-with-switch
  3. // tested in C17 (gcc)
  4.  
  5. #include <stdio.h>
  6.  
  7. int excuseMeWhatTheHeck(int,int);
  8.  
  9.  
  10. // takes 2 digits as commandline parameters: ./<file> <option> <condition>
  11. // condition is used as boolean
  12. int main(int argc, char const *argv[])
  13. {
  14.     if (argc < 3) {
  15.         printf("Not enough arguments (%d), expected 2\n (additional arguments will be discarded)\n", argc - 1);
  16.         return 1;
  17.     }
  18.  
  19.     int option = *argv[1] - 48;
  20.     int condition = *argv[2] - 48;
  21.  
  22.     printf("option: %d condition: %s return: %d\n", option, condition ? "true" : "false", excuseMeWhatTheHeck(option, condition));
  23.  
  24. }
  25.  
  26. int excuseMeWhatTheHeck(int option, int condition) {
  27.     switch(option) {
  28.         case 0:
  29.             if(condition)
  30.         case 1:
  31.         case 2:
  32.                 return 1;
  33.             else
  34.         case 3:
  35.         default:
  36.                 return 0;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment