场景如下:我有一大堆需要解析的事件,只传递我需要的事件。实现这一目标的最佳方法是什么?到目前为止,我的代码如下所示:
#include <stdio.h>
#include <string.h>
int main (int argc, char **argv) {
int i, j;
char events[4][15]; /* for the sake of the test only*/
char *ptr;
/* probably loaded from a config file */
const char *filter[] = {"first_event", "third_event"};
/* just preparing data so far */
strcpy(events[0], "first_event");
strcpy(events[1], "second_event");
strcpy(events[2], "third_event");
strcpy(events[3], "foo");
/* my approach is to have two iterations */
for (j = 0; j < 2; j++) {
for (i = 0; i < 3; i++) {
if (strcmp(filter[j], events[i]) == 0) {
printf("pass -> %s\n", events[i]);
continue;
}
}
}
}