Guys can't we use the transform function here like the one used in the following code?
Code:
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdlib>
int main()
{
char string[100];
char upString[100];
char lowString[100];
strcpy(string, "I have a nice red house and you're not gonna take it from me!");
unsigned int stringLength = 0;
for (unsigned int i = 0; string[i] != '\0'; i++)
stringLength++;
std::cout << "The original: " << string << "\n\n";
std::cout << "Now applying transform() to uppercase...\n\n";
std::transform(&string[0], &string[stringLength], &upString[0], toupper);
// This is equal to
// std::transform(string, string + stringLength, upString, toupper);
// but might make more sense
upString[stringLength] = 0;
std::cout << "upString: " << upString << "\n\n";
std::cout << "Now applying transform() to lowercase (it's a verb, yes)...\n\n";
std::transform(&string[0], &string[stringLength], &lowString[0], tolower);
lowString[stringLength] = 0;
std::cout << "lowString: " << lowString << "\n\n";
system("pause");
return 0;
}