Searching an array of structures

Hi,
I am trying to search an array of structures. There are only two elements in the array (structure one and structure two). But I cant seem to get the code to search both. It seems to search the first entry and then stop.

Here is a code snippet:

for (int index = 0; index < arraySize; index++)
{
if (items[index].itemname == stuff )
{

items[index].equip = 'y';

What I want it to do is search the array for "stuff" and if it finds a match, update items[index].equip to a 'y'. It updates the first one, but even though I know im typing in the second entry correctly, It does not find it.

Any help would be appreciated...Thanks!
Can I see the entire loop and the definition of an 'item'?
Hope this helps..


The definition of items:
//Structure decleration
struct bag
{
char itemname[50]; //item name
int stats; //equipment stats
char equip; //Is it equiped? y or n
};



//items of type bag
bag items[NUM_ITEMS];

Here is the code from the loop to the end:


for (int index = 0; index < arraySize; index++)
{
if (items[index].itemname == stuff )
{

items[index].equip = 'y';

fstream bagFile;
bagFile.open("bag.txt", ios::out | ios::binary);
if (bagFile.fail())

cout << "Error opening bag.txt!! Call Joe!";



else
{
bagFile.write(reinterpret_cast<char *>(&items),
sizeof(items));
bagFile.close();





bagFile.open("bag.txt", ios::in|ios::binary);
(bagFile.read(reinterpret_cast<char *>(&items),
sizeof(items)));
bagFile.close();


cout << right;
cout << "****************************************************************\n";
cout << "*" << setw(20) << " Equipment" << setw(30) << "*\n";

for (int index = 0; index < arraySize; index++)
{

cout << "* Name: " << setw(28)<< items[index].itemname << setw(29) << "*\n";
cout << "* Stats: " << setw(20) << items[index].stats << setw(29) << "*\n";
cout << "* Equiped: " << setw(20) << items[index].equip << setw(29) << "*\n";


}
cout << "****************************************************************\n";
cout << "\n";
cout << "\n";
cout << "\"A\" Return to game. \"B\" Quit. \"C\" Equip an item.\n";
cin >> selection;


}
}
else
{
cout << "Item not found\n";
getStats();
}
}

}
else
{
cout << "Invalid selection. Try again.";
getStats();
}
}
}
}
}
Topic archived. No new replies allowed.