3 ms·
I wasn't aware you could use const char pointers in switch statements. switch (var) { case "foo": printf("foo block."); break; case "
by chollida1 17y ago
I wasn't aware you could use const char pointers in switch statements.
switch (var) {
case "foo":
printf("foo block.");
break;
case "bar":
printf("bar block.");
break;
default:
printf("Default case")
}
- mbrubeck 17y agoYou can't: $ cat foo.c #include <stdio.h> main() { const char *foo = "bar"; switch (foo) { case "foo": printf("foo\n"); } } $ gcc -pedantic -std=c99 foo.c -o foo foo.c: In function ‘main’: foo.c:4: error: switch quantity not an integer foo.c:5: error: case label does not reduce to an integer constant
- chollida1 17y agoSorry to make you put in so much work. I'm aware that you can't do this. I guess my sarcasm didn't translate:)