I know this function looks messy- but i have tried sooo many ways to fix this and I cant. I am pretty sure my for loop is the one thats messed up but i cant figure out how to fix it. Its the same thing as the earlier post but i have it working better now. I have 8 names in datafile, but some are repeats. Example:
Code:
jEnna
PArrish
KURt
JoYce
whitNEY
Jenna
whitney
KURT
I want it to read the name into temp- compare it with the names in the array and if it is not in the array- send it to fix name (which it is doiing with all of them) and then put it in the next space in my array(list). If it is already in the array then i just discard it and move on to the next one. I think i have the for loop and maybe the if stmt messed up. I am going crazy.
Code:
void countnames(string list [], int& count, ifstream& inputfile, ofstream& outputfile)
{
string temp;
count = 0;
inputfile >> temp;
while(!inputfile.eof())
{
for(int i = 0; i < MAX; i++)
{
if (temp != list[count])
{
temp = fixname(temp);
count++;
list[count] = temp;
}
else if (temp == list[count])
{
inputfile >> temp;
}
inputfile >> temp;
}
inputfile >> temp;
}
outputfile << "# of unique names: " << count << endl;
Here is what it is outputting:
Code:
Jenna
Joyce
Kurt
Parrish
Whitney
Jenna
Whitney
Help!