How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / prakash
Another version that actually reverses the string...
#include <stdio.h>
char *reverse(char *sstr, char *str, char c)
{
if (*str == '\0')
return sstr;
sstr = reverse(sstr, str+1, *(str+1));
*sstr = c;
return (sstr+1);
}
int main()
{
char str[100];
printf("Enter the string: ");
scanf("%s", str);
reverse(str, str, *(str + 0));
printf("Reversed string: %s\n", str);
return 1;
}
| Is This Answer Correct ? | 25 Yes | 11 No |
Post New Answer View All Answers
How do I swap bytes?
What are logical errors and how does it differ from syntax errors?
How can I automatically locate a programs configuration files in the same directory as the executable?
Write a program which returns the first non repetitive character in the string?
Compare and contrast compilers from interpreters.
i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical
Is there any data type in c with variable size?
What does == mean in texting?
What is the difference between memcpy and memmove?
What is memory leak in c?
c program to compute AREA under integral
how to construct a simulator keeping the logical boolean gates in c
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
Without Computer networks, Computers will be half the use. Comment.
What is the main difference between calloc () and malloc ()?