I'm having a problem with my search function for my linked list. It has to do with my foodItem object. I'm not sure what to replace it with since it's part of the function protocol. The previous version of this code used an array and part of my problem is correctly converting to a linked list format. I'm really stuck, so any advice would be much appreciated. I hope I didn't leave out anything helpful. :confused: --Sheila
/**
*searchByName:search for foods by name
*in:name
*out:foodItem
*return:true if there is a match, or else false
**/
bool FoodList::searchByName(char name[],Food& foodItem)const
{
int i;
size = foodItem.size;
Node * current;
if(foodItem.head == NULL)
head = NULL;
else
{
for(current=head;current;current=current->next)
{
if(strcmp(head->data.name,name) == 0)
{
strcpy(head->data.name,foodItem.head->data.name);
head->data.category = foodItem.head->data.category;
head->data.calories = foodItem.head->data.calories;
head->data.carbohydrates = foodItem.head->data.carbohydrates;
head->data.fat = foodItem.head->data.fat;
head->data.cholesterol = foodItem.head->data.cholesterol;
head->data.sodium = foodItem.head->data.sodium;
head->data.protein = foodItem.head->data.protein;
return true;
}
else{
}
return false;
}