Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321

3728


How macro execution is faster than function ?

1197


Tell us bitwise shift operators?

1095


Explain how can you check to see whether a symbol is defined?

1203


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.?

1073


Why is c fast?

1069


What are lookup tables in c?

1005


What are the Advantages of using macro

1177


Who invented bcpl language?

1198


If I have a char * variable pointing to the name of a function ..

1173


why return type of main is not necessary in linux

2110


How does placing some code lines between the comment symbol help in debugging the code?

1003


What is use of #include in c?

1170


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);

1885


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.

2060