I have a struct that looks like this:
typedef struct dictionary_t{
char word[30];
int foo;
int bar;
} dictionary_t;
Which forms an ordered array:
dictionary_t dictionary[100];
I would like to search this array for a string using bsearch() and get a pointer to the struct. So far this has worked:
dictionary_t* result;
char target[30] = "target";
result = bsearch(&target, dictionary, dict_length, sizeof(dictionary_t), (int(*)(const void*,const void*)) strcmp);
However this is a bit of a hack and only works because the string happens to be the first member of the struct. What would be a better way to find a string within an array of structs and return a pointer to the struct?