#include<iostream>
#include<cctype> // <-- this is the standard header name
usingnamespace std;
int main()
{
char string1[]="THE";
char string2[]="there";
for(int i=0; string1[i]!='\0'; i++)
{
string1[i] = (tolower(string1[i]));
}
for(int i=0; string2[i]!='\0'; i++) // <-- Notice how I used two loops, one for each string
{
string2[i] = (toupper(string2[i]));
}
cout << "string1 is " << string1 << endl; // <-- Watch your indentation
cout << "string2 is " << string2 << endl;
return 0;
}
@biplav
Don't teach people to use system("PAUSE").
I didn't mind it for stupid stuff in the past, but seeing as it is such an endemic problem, I now take pains to remind everyone that it is a really, really bad idea.
...you could, but then you would be counting through to find the string length every time you go through the loop. By stopping with the indexed character is null, you do the same thing as strlen(), but only once.
You could also cache the value:
1 2
for (size_t len = strlen(string1), i = 0; i < len; i++)
...
I was thinking that the null character is always going to be the last character, otherwise it's not a cstring, but instead just a normal character array.