Recursive reverse of a string.

Joined
Oct 4, 2007
Messages
4
Reaction score
0
I have written a recursive reverse of string and storing the value in a destnation string.Given below.
Can any one suggest improvements?

int main()
{
char * str = NULL;
int count = 0;
Reverse("abcd",&str,count);
}
void Reverse(char * source, char ** dest,int& count)
{
count++;
if(*(source))
{
int index = count+1;
Reverse(source+1,dest,count);
(*dest)[count-index] = source[0];

}
else
{
*(dest) = new char[count];
memset((*dest),0,count);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,156
Latest member
KetoBurnSupplement
Top