Could you please help me in correcting my code:
This is a function that returns a pointer to struct item:
struct item* findItem(const char* key) {
for (int i = 0; i < nItems; i++) {
if (!strcmp(items[i].key, key)) { return &items[i]; }
}
return NULL;
}
From main function, I want to retrieve my struct value as following:
struct item search_items = findItem(&key) ; // I have problem with this line
char* itemValue;
if (search_items != NULL)
{
itemValue = search_items->value;
}
How can I retrieve the structure and save it to be used in the main function?
itemValueiffindItemreturns NULL.