Tran-Gate 0 Report post Posted October 17, 2008 // Reverse case using array indexing. #include <iostream>#include <cctype> using namespace std; int main(){ int i; char str[80] = "This Is A Test"; cout << "Original string: " << str << "\n"; for(i = 0; str[i]; i++) { if(isupper(str[i])) str[i] = tolower(str[i]); else if(islower(str[i])) str[i] = toupper(str[i]); } cout << "Inverted-case string: " << str; return 0; } In the for statement, how is the condition str? I am confused!! Thanks in advance!! Share this post Link to post Share on other sites
Nabb 0 Report post Posted October 17, 2008 (edited) I don't know C++ specifically, but I'd assume that: str returns the ith position in the string of str str returns undefined for anything after 'This Is A Test' undefined evaluates to false (i.e. breaks the loop), while any character (e.g. "i", "A") evaluates to true. Edited October 17, 2008 by Nabb (see edit history) Share this post Link to post Share on other sites