How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / mahesh auti
#include<stdio.h>
#include <string.h>
char * reverse (char *); //function prototype
int length(char *); //function prptotype
void main()
{
int i;
char *str, *rev;
clrscr();
gets(str);
strcpy(rev,reverse(str));
printf("Original %s Reverse %s", str, rev);
free(str);
free(rev);
getch();
}
int length(char *s)
{
int i;
for (i=0; *(s+i)!='\0' ; ++i);
return i;
}
char *reverse(char *s)
{
char *t;
int i, n;
n=length(s);
for (i=0; i<n; ++i)
{
*(t+i)=*(s+n-1-i);
}
*(t+i)='\0';
printf("\nOUT: %s\n", t);
return t;
}
| Is This Answer Correct ? | 17 Yes | 27 No |
Post New Answer View All Answers
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321
How macro execution is faster than function ?
Tell us bitwise shift operators?
Explain how can you check to see whether a symbol is defined?
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
Why is c fast?
What are lookup tables in c?
What are the Advantages of using macro
Who invented bcpl language?
If I have a char * variable pointing to the name of a function ..
why return type of main is not necessary in linux
How does placing some code lines between the comment symbol help in debugging the code?
What is use of #include in c?
What will the code below print when it is executed? int x = 3, y = 4; if (x = 4) y = 5; else y = 2; printf ("x=%d, y=%d ",x,y);
Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.