Make an array of struct Food
like this:
#define MAX_FOODS (8)
struct Food foods[MAX_FOODS] = {
{"apple", 0, FRUIT},
{"carrot", 1, VEGGIE},
{"candy", 2, DESSERT},
...
};
This way, it'll be easy to search and index.
int i = LookupFunc("apple");
int LookupFunc(char *str)
{
for(int i = 0; i < MAX_FOODS; i++)
{
if(strcmp(foods[i].name, str) == 0)
return i;
}
return -1; // Not found
}