Skip to content

Instantly share code, notes, and snippets.

@ukitazume
Created December 9, 2011 04:42
Show Gist options
  • Save ukitazume/1450200 to your computer and use it in GitHub Desktop.
Save ukitazume/1450200 to your computer and use it in GitHub Desktop.
#include <stdio.h>
# liner serch
int lookup(char *word, char *array[]) {
int i;
for (i = 0; array[i] != NULL; i++) {
if (strcmp(word, array[i]) == 0)
return i;
}
return -1;
}
int main (int argc, const char * argv[])
{
char *flab[] = {
"test",
"hoge",
"ukita",
"ukitazume",
NULL
};
char *target = "ukitazume";
int result = lookup(target, flab);
printf("%d", result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment