I am trying to read in from a file, remove numbers, and hyphens so that the output of this...

1. HellO does- This Work
would be...

hello does this work
I believe this code works the way I expect it too...however, i copied a large amount of text from the internet and pasted it into a text document. The program gets a runtime error...

Debug Assertion Failed!
...
Expression: (unsigned)(c+1)<=256
...
To troubleshoot I took a very small part of the text and ran it and retyped any non alpha-numeric characters. This worked, however there is way too much text to go through line by line and replace...actually that would defete the purpose of having this program. I am guessing that the text contains non-standard types of characters? Any ideas on how to go about this? Thanks.

Code:
void formatText(string filename)	
{
    ifstream fin(filename.c_str());
    ofstream formatout("format.txt");
    
    string word;
    while (fin >> word)
    {
        int x;
        int length = word.length();
        for (x = 0; x < length; x++)
        {
	    char c = word[x];
	    if (isalpha(c))				//checks for letter
	    {
  	        c = tolower(c);			     //makes lowercase
	        formatout << c;
	    }
	    else if (c == '-')			       //removes hyphens
	        formatout << " ";
	}
        formatout << " ";
    }
}