fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. #define STRSWITCH(s) do{\
  7.   bool flag_=false;\
  8.   char*switchstr_=(s);\
  9.   int switchstrlen_=strlen(switchstr_);{{
  10.  
  11. #define STRCASE(s) \
  12.   }}{\
  13.   char*casestr_=(s);\
  14.   int casestrlen_=strlen(casestr_);\
  15.   flag_=flag_||switchstrlen_==casestrlen_&&!strncmp(switchstr_,casestr_,casestrlen_);\
  16.   if(flag_){
  17.  
  18. #define STRSWITCHDEFAULT }}{{
  19. #define ENDSTRSWITCH }}}while(0);
  20.  
  21. void test(char *str)
  22. {
  23. printf("case \"%s\":\n", str);
  24. STRSWITCH (str)
  25. STRCASE("hui")
  26. puts("hui");
  27. STRCASE("pizda")
  28. puts("pizda"); break;
  29. STRCASE("G-goorda")
  30. puts("G-goorda");
  31. STRSWITCHDEFAULT
  32. puts("default");
  33. ENDSTRSWITCH
  34. }
  35.  
  36. int main(void)
  37. {
  38. test("govno");
  39. test("hui");
  40. test("pizda");
  41. test("G-goorda");
  42. return 0;
  43. }
Success #stdin #stdout 0s 4384KB
stdin
Standard input is empty
stdout
case "govno":
default
case "hui":
hui
pizda
case "pizda":
pizda
case "G-goorda":
G-goorda
default