Hello, I'm trying to have my program locate any duplicate strings in an array, say, there were two instances of the word 'man', it would add 1 to the Word Amount of that word, and move the duplicate to the back of the array in some way. The problem is, I cannot figure out for the life of me how to do this correctly. As of right now, when I try to run the program, it'll find the first duplicate and add 1 to the word amount of that word, but then it goes wonky and adds an empty line as an entry in the array and won't recognize any more same words. Here's what I've got so far, the beginning is me using a selection sort to sort the array, the else if statement is where I'm having problems.
void sortArray(WordStruct Words[1000], int &itemamount)
{
int i, minIndex;
string temp;
for (i = 0; i < itemamount; i++)
{
minIndex = i;
for (int j = i + 1; j < itemamount; j++)
{
if (Words[minIndex].Word > Words[j].Word)
{
temp = Words[minIndex].Word;
Words[minIndex].Word = Words[j].Word;
Words[j].Word = temp;
}
else if (Words[minIndex].Word == Words[j].Word)
{
Words[minIndex].WordAmt++;
temp = Words[j].Word;
Words[j].Word = Words[999].Word;
Words[999].Word = temp;
itemamount--;
}
}
cout << Words[i].Word << endl << Words[i].WordAmt << endl;
}
}