Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <strings.h>
  4.  
  5. #define SWITCH_STR(_x) for(const char* _t = (_x); _t; _t = NULL) if (0)
  6. #define CASE_STR(_str) } else if (strcasecmp(_str, _t) == 0) {
  7. #define DEFAULT_STR } else {
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.     if (argc < 2)
  12.     {
  13.         fprintf(stderr, "Usage: %s str\n", argv[0]);
  14.         exit(EXIT_FAILURE);
  15.     }
  16.     SWITCH_STR(argv[1])
  17.     {
  18.         CASE_STR("hello")
  19.         {
  20.             printf("Hello world!\n");
  21.         }
  22.         CASE_STR("bye")
  23.         {
  24.             printf("Goodbye world!\n");
  25.         }
  26.         DEFAULT_STR
  27.         {
  28.             printf("No idea\n");
  29.         }
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement