Thank you to everybody for the help, I solved the problem and I included the working code on the end for the ones who have the same problem.
I am trying to write a simple function which cleans the string variable from none letter characters and turn the variable to all lowercase.
For example,
"h4el>lo" to "hello".
"BIG" to "big".
The only exception is (') apostrophe mark because of the words like (can't).
The code I wrote work perfectly in normal conditions.
string CleanTheWord(string word)
{
string cleanWord = "";
for (int i = 0; i < word.length(); i++)
{
if (islower(word[i]))
{
cleanWord += word[i];
}
else if (isupper(word[i]))
{
cleanWord += tolower(word[i]);
}
else if (word[i] == 39 || word[i] == 44) //Apostrophe mark
{
cleanWord += word[i];
}
}
return cleanWord;
}
Problem is I need to apply this function to some big amount of variables and even if there is no problem with most of it, some variables contain uncommon characters. For example, the weird string value which causes the "Debug Assertion Failed Error" is:
she�s
And the error I am taking is:
Debug Assertion Failed
program: //program path
File minkernel\crts\ucrt\src\appcrt\convert\isctype.cpp
Line: 36
expression c>=-1 && c <=255
I want to be able to convert "she�s" to "shes" (removing none letter characters "�").
Or if it is not possible I want to at least ignore problematic words so the program will not crash and continue as normal.
--------- Working Code ---------
string CleanTheWord(string word)
{
string newWord = "";
for (int i = 0; i < word.length(); i++)
{
char control = word[i] < 0 ? 0 : word[i];
if (isupper(control))
{
newWord += tolower(control);
}
else if (isalpha(control) || control == '\'')
{
newWord += control;
}
}
//cout << "Final result: " << newWord << endl;
return newWord;
}