QUOTE(VernonDozier @ 21 Jan, 2008 - 08:33 PM)

CODE
temp4 = sortedwordlist.size();
Ok I took that out, didn't see that.
QUOTE(VernonDozier @ 21 Jan, 2008 - 08:33 PM)

I'm not sure what the "sort" section is supposed to do, but it did not sort the words I put into "wordlist.txt". I did notice that you were using the "==" operator when comparing strings, which can get dangerous and have bad results. Instead, consider using the "compare" function from the "string" library when you want to compare strings.
Ok, I changed the string comparisons to str1.compare(str2) == 0.
QUOTE(VernonDozier @ 21 Jan, 2008 - 08:33 PM)

This line in the "scramble" section seemed odd:
CODE
fstream wordslist;
Didn't see that either, something like that should bring up a compiler error, but maybe as you said, there is some other thing we don't know about.
QUOTE(VernonDozier @ 21 Jan, 2008 - 08:33 PM)

I am a little confused by the scrambling and unscrambling part of all this. Are you scrambling and unscrambling each individual word so that the word changes or are you keeping the words the same and scrambling and unscrambling the list? It looks like you are trying to take a word and put the letters in that word in abc order. You seem to also be doing the same thing here twice with two different vectors of strings:
CODE
for (int p=0;p<sortedwordlist.size();p++)
{
sort(sortedwordlist[p].begin(), sortedwordlist[p].end());
}
for (int p=0;p<scrambledwords.size();p++)
{
sort(scrambledwords[p].begin(), scrambledwords[p].end());
}
If you could explain what all of the different files are supposed to represent, what should be in those files both before and after, and what you are trying to do, that would help because I'm a little confused. It looks like you are treating each word as a vector of characters and trying to use an iterator to sort them, but I see no iterator declared anywhere. I could be way off here. For sure, though, don't use the "==" operator to compare your strings.
What that code above does is take each individual words in the vectors sortedwordlist and scrambledwords and alphabetizes the letters in it. Then it compares them to see if it is equal to anything in the wordlist. Example: I have a scrambled word 'pyaph', and I have another word 'happy'. What the sort does is arrange it by letter, so both pyaph and happy get arranged to: ahppy. That means that both are equal and that 'pyaph' was just the scrambled word 'happy'. Hope I explained it ok

Ok, this is what I changed the code to, it comes out in the right order now but there is always duplicate of the last word. Any ideas?
CODE
{ // Start the unscramble code
string str1;
string str2;
cout << "** Commencing Word Unscramble **" << endl;
vector<string> wordlist;
vector<string> scrambledwords;
vector<string> sortedwordlist;
string temp;
scrambled.open("scrambled.txt");
cout << "** Gathering Scrambled Words **" << endl;
while (!scrambled.eof())
{
scrambled >> temp;
scrambledwords.push_back(temp);
}
scrambled.close();
wordslist.open("wordlist.txt");
unscrambled.open("unscrambled.txt");
wordlist.resize(0);//wordlist resize spot
cout << "** Gathering Wordlist **" << endl;
while (!wordslist.eof())
{
wordslist >> temp;
wordlist.push_back(temp);
}
sortedwordlist.resize(0);//sorted word list resize spot
for (unsigned int i=0;i<wordlist.size();i++)
{
sortedwordlist.push_back(wordlist[i]);
}
for (unsigned int i=0;i<sortedwordlist.size();i++)
{
sort(sortedwordlist[i].begin(), sortedwordlist[i].end());
}
for (unsigned int i=0;i<scrambledwords.size();i++)
{
sort(scrambledwords[i].begin(), scrambledwords[i].end());
}
cout << "** Checking Scrambled Words Against Wordlist **" << endl;
for (unsigned int i=0;i<scrambledwords.size();i++)
{
str1 = scrambledwords[i];
for (unsigned int j=0;j<sortedwordlist.size();j++)
{
str2 = sortedwordlist[j];
if (str1.compare(str2) == 0)
{
cout << wordlist[j] << endl;
unscrambled << wordlist[j] << ",";
}
}
}
cout << "** Finished Unscrambling Words **\n" << endl;
wordslist.close();
unscrambled.close();
break;
This post has been edited by devilsson2010: 22 Jan, 2008 - 12:37 PM