The code in the following, could you point out what is wrong? Why is it wrong? Thanks for your inputs.
Code:void reverseString(const char* str1, char* str2) { int len = strlen(str1); str2 = new char[len+1]; char* p = const_cast<char*>(str1) + len - 1; while(p>=str1) { *str2++ = *p--; } *str2 = '\0'; } int main() { const char* s1 = "Tony"; char* s2; reverseString(s1, s2); cout<<s2<<endl; return 0; }




Reply With Quote