In place string reversal throws exception ...
-
Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }
redindian
-
Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }
redindian
-
Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }
redindian
That's not very maintainable.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }
redindian
given that this is the C++/MFC forum, why not look at CString::MakeReverse()
-
Hi all I am running a piece of code and it asserts . Any ideas why so ? . I use VC++ 6.0 Dialog based application char* one ="hello"; StrRev(one); ..... ..... void StrRev(char *s) { for(char *end = s + (strlen(s) - 1); (end > s) ; --end, ++s) { char tmpChar = (*s); (*s) = (*end); <---- it throws exception here ....why ? (*end) = tmpChar; } }
redindian
dharani wrote:
(*s) = (*end); <---- it throws exception here ....why ?
Why have you not bothered to use the debugger to answer such a question? By looking at the values of those variables as the program runs, you'll no doubt see exactly what is happening, and learn a valuable lesson along the way.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
given that this is the C++/MFC forum, why not look at CString::MakeReverse()
I think he was either inspired by my recent what-happened-at-the-interview stories in the lounge, or he's got an interview himself.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001