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

What will the preprocessor do for a program?

1016


Implement bit Array in C.

1096


how logic is used

1917


Describe the order of precedence with regards to operators in C.

1002


Is python a c language?

948


What is difference between structure and union with example?

989


What functions are used in dynamic memory allocation in c?

1017


Can we use any name in place of argv and argc as command line arguments?

1011


differentiate built-in functions and user – defined functions.

1039


Can we access the array using a pointer in c language?

995


How can you invoke another program from within a C program?

1023


What is dynamic dispatch in c++?

992


What is structure and union in c?

1070


Are bit fields portable?

1108


formula to convert 2500mmh2o into m3/hr

941