Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <strings.h>
- #define SWITCH_STR(_x) for(const char* _t = (_x); _t; _t = NULL) if (0)
- #define CASE_STR(_str) } else if (strcasecmp(_str, _t) == 0) {
- #define DEFAULT_STR } else {
- int main(int argc, char *argv[])
- {
- if (argc < 2)
- {
- fprintf(stderr, "Usage: %s str\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- SWITCH_STR(argv[1])
- {
- CASE_STR("hello")
- {
- printf("Hello world!\n");
- }
- CASE_STR("bye")
- {
- printf("Goodbye world!\n");
- }
- DEFAULT_STR
- {
- printf("No idea\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement