write a C code
to reverse a string using a recursive function, without
swapping or using an extra memory.

Answer Posted / mohan

#include <stdio.h>
#include <string.h>

void reverse(char **s, int start, int last)
{
char tmp;
if (start >= last)
return;
char *s2 = *s;
tmp = s2[start];
s2[start] = s2[last];
s2[last] = tmp;
reverse(s, start + 1, last - 1);
}
int main()
{
char *s = strdup("Hello World");
printf("%s\n", s);
reverse(&s, 0, strlen(s) - 1);
printf("%s\n", s);
}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a C program in Fibonacci series.

628


What are the 32 keywords in c?

627


How can I do graphics in c?

586


What is the difference between test design and test case design?

1564


Why is sizeof () an operator and not a function?

573






What is s in c?

607


Why header file is used in c?

571


What are the functions to open and close the file in c language?

589


What is the difference between near, far and huge pointers?

627


5 Write an Algorithm to find the maximum and minimum items in a set of ā€˜nā€™ element.

1576


Which header file is used for clrscr?

571


Why use int main instead of void main?

590


What is an identifier?

618


What is 2 d array in c?

549


What is Dynamic memory allocation in C? Name the dynamic allocation functions.

553