Skip to content

Instantly share code, notes, and snippets.

@tkihira
Created March 22, 2012 19:09
Show Gist options
  • Save tkihira/2161882 to your computer and use it in GitHub Desktop.
Save tkihira/2161882 to your computer and use it in GitHub Desktop.
switch hack on C
void switch_func(int n) {
char *s;
switch(n) {
case 0:
s = "Sun";
if(0)
case 1:
{ s = "Mon"; }
if(0)
case 2:
{ s = "Tue"; }
if(0)
case 3:
{ s = "Wed"; }
if(0)
case 4:
{ s = "Thu"; }
if(0)
case 5:
{ s = "Fri"; }
if(0)
case 6:
{ s = "Sat"; }
printf("Today is %s\n", s);
break;
default:
printf("invalid number\n");
break;
}
}
void print_day(char *s) {
printf("Today is %s\n", s);
}
void switch_func(int n) {
char *s;
switch(n) {
case 0: s = "Sun"; print_day(s); break;
case 1: s = "Mon"; print_day(s); break;
case 2: s = "Tue"; print_day(s); break;
case 3: s = "Wed"; print_day(s); break;
case 4: s = "Thu"; print_day(s); break;
case 5: s = "Fri"; print_day(s); break;
case 6: s = "Sat"; print_day(s); break;
default: printf("invalid number\n"); break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment