Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C Programming

Name: Anonymous 2012-04-19 13:05

Hi /prague/
I'm programming in C and writing a little interactive program.
What's the best way to execute a function / piece of code depending on a string ? I could write a bunch of }else if(!strcmp(s, foo)){ but I find this hideous.
Any suggestions ?

Name: Anonymous 2012-04-19 14:27


struct command_handler_lst {
  struct command_handler_lst * next;
  char * name;
  void (*handler)();
};

for (; node; node = node->next) {
  if (strcmp(node->name, input) {
    node->handler();
  }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List