Here's code from something I was doing the other-night:
string str = "I'm a fairy! abc xyz ABC XYZ";
int casechanged = 0;
cout << str;
for(i = 0; i < str.length(); i++)
{
if(isUpper(str[i])) { str[i] = toLower(str[i]); casechanged = 1; }
if(isLower(str[i]) && casechanged != 1) { str[i] = toUpper(str[i]);}
casechanged = 0;
}
cout << str;
for(i = 0; i < str.length(); i++)
{
if(isLower(str[i])) { str[i] = toUpper(str[i]); casechanged = 1; }
if(isUpper(str[i]) && casechanged != 1) { str[i] = toLower(str[i]); }
casechanged = 0;
}
cout << str;
The isLower/Upper(), and toUpper/toLower(), are my own functions I wrote, just replace them with the proper names of the ones you're using.
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
Offline 1,270 posts
since Nov 2008