Program Stops Responding

I wrote this program to take a scrambled word and unscramble it using a list of words in a document. I got this program written that works for the first 15 words, but then it stops responding. Can anyone help me figure out the problem? Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <fstream>
#include <string>
#include <list>

using namespace std;

int CountCharacter(ifstream& Text, char CompareCharacter);
string ReadLine(ifstream& Text);
bool CompareByCharacter(string Text1, string Text2);

int main()
	{
		ifstream ListFile("wordlist.txt");//Load the word list
		if (ListFile.is_open())
			{//If it loaded successfully
				unsigned int CurrentWordCount = CountCharacter(ListFile, '\n');//Count the number of line breaks (aka the number of words)
				if (CurrentWordCount == 0)
					{//If the number of words is 0
						ListFile.close();//Close the list and inform the user.
						cout << "\"wordlist.txt\" is empty." << endl;
					}
				else
					{
						list<string> WordList;//Create a list for the words
						for (unsigned int i = 0; i <= CurrentWordCount; ++i)
							{WordList.insert(WordList.end(), ReadLine(ListFile));}//Load all of the words from the document into the list
						ListFile.close();//Close the list

						//Request and load the word which needs to be unscrambled
						string ScrambledWord;
						cout << "Enter scrambled word: \n" << endl;
						getline(cin, ScrambledWord);

						for (list<string>::iterator i = WordList.begin(); i != WordList.end(); i++)
							{//For the length of the word list,
								if (!CompareByCharacter(*i, ScrambledWord))//Check each word to see if it has the same character composition as the word entered
									{WordList.erase(i);}//If it doesn't, erase the word.
								else//Otherwise, end the loop immediately.
									{break;}
							}
						if (WordList.size() == 0)//If the word list is empty, inform the user.
							{cout << "No match found." << endl;}
						else//Otherwise, present the first word of the list.
							{cout << WordList.front() << endl;}
					}
			}
		else//Else, notify the user that the file could not be opened
			{cout << "Could not open file, \"wordlist.txt\"." << endl;}
		return 0;
	}

int CountCharacter(ifstream& Text, char CompareCharacter)
	{//Count the number of times a character occurs in an ifstream.  Takes the ifstream which it searches, and a character to look for.
		ifstream::pos_type OriginalPosition = Text.tellg();//Tract the original position so that it may be returned there once done.
		Text.seekg(0);//Go to the beginning of the file.
		int Count = 0;//Create a count variable which will be returned.
		while (Text.good())
			{//While we are able to work within the file,
				char CurrentCharacter;//create a character and fill it with the next character from the file.
				Text.get(CurrentCharacter);
				if (CurrentCharacter == CompareCharacter)
					{Count++;}//If the character is the same as the one provided, add one to the count and repeat.
			}
		Text.clear();//Clear the error state (we should have gotten an error after reaching the end of the file).
		Text.seekg(OriginalPosition);//Return to the original position.
		return Count;//Return the count.
	}

string ReadLine(ifstream& Text)
	{//Return a line from an ifstream.  Takes an ifstream to be read.
		string Line;//Create a string which we will return
		while(Text.good())
			{//While we are able to work with the file,
				char CurrentCharacter;//create a character and fill it with the next character from the file.
				Text.get(CurrentCharacter);
				if (CurrentCharacter != '\n')//If the character isn't a line break, add it to the string.
					{Line += CurrentCharacter;}
				else//Else, end the loop, jumping strait to the "return" statement
					{break;}
			}
		return Line;//Return the Line
	}

bool CompareByCharacter(string Text1, string Text2)
	{//Check two strings to see if their character composition is the same.  Takes two strings, Text1 and Text2, which are compared.
		for (unsigned int i = 0; i < Text1.length(); i++)
			{//For the length of the first string,
				size_t Position = Text2.find_first_of(Text1[i]);//find the position of each character of the first string in the second string.
				if (Position == string::npos)
					{return false;}//If the character isn't there, they aren't the same.
				else//If it is, remove it. This prevents a character from being counted twice so that this doesn't happen: CompareByCharacter("clock", "lock") == true
					{Text2.replace(Position, 1, "");}
			}
		return true;//Return true since all the characters were found
	}


And a shortened vertion of the list:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

rambo1
charlie1
david1
digital1
dragon1
honda1
shadow1
eagle1
freak1
james1
1sanjose
apple1
master1
happy1
martin1
jason1
larry1
number1
robert1
soccer1
direct1
chester1
welcome1
french1
hockey1
chevy1
scooter1
chris1
lucky1
teddy1
phoenix1
hello1
julie1
kevin1
pookie1
viper1
jenny1
jesus1
kelly1
money1
mouse1
sting1
justin1
molly1
sunny1
front242
jordan23
2welcome
h2opolo
bird33
4runner
Have you tried using a debugger?
It goes into some bizar stuff that I can't really understand. I'm still relatively new.
closed account (zb0S216C)
@Dornith: Post the debugging information. Also, take it easy with the space-bar.

Wazzak
Topic archived. No new replies allowed.