Or you could iterate through the string and check manually with something like:
1 2 3 4 5 6 7 8
if(str[i] >= 'a' && str[i] <= 'z') //lowercase found
{
str[i] -= ' '; //'a' == 97, 'A' == 65, ' ' == 32, if you prefer you can subtract 32
}
elseif(str[i] >= 'A' && str[i] <= 'Z') //uppercase
{
str[i] += ' '; //as mentioned earlier
}
Looking at your code earlier it looks like you can use the to/is(upper/lower) functions so use those instead of what I mentioned.
To get your code working you should check if the character is tolower(or upper) then either make it upper or lower depending so instead of: xstring[i] = toupper(xstring[i]); try something like:
[edit]
You seem to know what iterators are based on your reverse function why not iterate over the string instead of using a 0->n loop?
1 2 3 4 5 6 7 8 9
for(constauto &it : str) //you can use char instead of auto I suppose
{
// 'it' is the character
}
for(auto it = str.begin(); it != str.end(); ++it)
{
// '*it" is the character
}
if(str[i] >= 'a' && str[i] <= 'z') //lowercase found
{
str[i] -= ' '; //'a' == 97, 'A' == 65, ' ' == 32, if you prefer you can subtract 32
}
elseif(str[i] >= 'A' && str[i] <= 'Z') //uppercase
{
str[i] += ' '; //as mentioned earlier
}
That is a bit obfuscated. The space character has nothing to do with the conversion from or to different cases, logically speaking. It just happens to have the same value in ascii as the distance from 'a' to 'A'.