toupper() & tolower() problem?
The following code converts the string copied to uppercase and then to lowercase again.
Code:
// Convert a string to uppercase & lowercase
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cctype>
using namespace std;
int main()
{
char str[80];
int i;
strcpy(str, "This is copied to str");
for(i=0;str[i];i++)
str[i]=toupper(str[i]);
cout << str;
for(i=0;str[i];i++)
str[i]=tolower(str[i]);
cout << "\nOriginal str was ( " << str << " )\n\n";
system("pause");
return 0;
}
The problem is I cannot make it work without a second for loop. I don't want to use the second for loop, instead any other way if possible.