Skip to content

Instantly share code, notes, and snippets.

@Arachnid
Created December 11, 2012 11:03
Show Gist options
  • Save Arachnid/4257798 to your computer and use it in GitHub Desktop.
Save Arachnid/4257798 to your computer and use it in GitHub Desktop.
typedef void (*command_handler)(char*);
struct command_t {
char *command;
command_handler handler;
} commands[] = {
{"command1", func1},
{"command2", func2},
{NULL, NULL}
};
// ...
for(int i = 0; commands[i].command != NULL; i++) {
if(strcmp(commands[i].command, input) == 0) {
commands[i].handler(data);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment