Since this is C++, I would just stick with
std::string unless you have a real reason to use
char
arrays instead (and even if you do, you can just use the
.c_str() member function of
std::strings instead).
That being said, on line 36, it should be
1 2
|
delete[] output;
delete[] reverse;
| |
since you allocated them using
new[]
.
Also, I don't think you can put them both on one line like that, because it'll only delete the first one. (Look up the comma operator here:
http://www.cplusplus.com/doc/tutorial/operators/ . Basically,
delete output, reverse;
runs
delete output;
and then returns
reverse
)
But really, you should be using
std::string.
If you're not being required to write your own reverse function (i.e. for an assignment), there's a really easy way to reverse a string:
1 2 3
|
std::string str = "Hi there!";
std::string reverse(str.rbegin(), str.rend());
std::cout << reverse;
|
!ereht iH | |
If you need/want to reverse in-place, look at
std::reverse:
http://www.cplusplus.com/reference/algorithm/reverse/