Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int myfunc(char *str, int val)
- {
- struct {
- char *name;
- int data;
- } table[] = {
- {"foo", 1},
- {"bar", 2},
- {"baz", 3},
- {"abc", 4},
- {"123", 5},
- {NULL, NULL, 0}
- };
- static int DEFAULT_DATA = -1;
- for (int i = 0; table[i].name; i++) {
- if (strcmp(str, table[i].name) == 0) {
- return some_fancy_function(val, table[i].data);
- }
- }
- return some_fancy_function(val, DEFAULT_DATA);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement