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

Explain why can’t constant values be used to define an array’s initial size?

1398


Can a pointer be volatile in c?

1038


Explain why c is faster than c++?

1124


How can I check whether a file exists? I want to warn the user if a requested input file is missing.

1202


Why does notstrcat(string, "!");Work?

1203


What is property type c?

1130


What is function pointer c?

1181


Why do we use return in c?

1043


In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)

2171


Write a program to check palindrome number in c programming?

1062


The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this

3656


How can I do peek and poke in c?

1135


Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)

1206


Write a program to find the biggest number of three numbers in c?

1090


Difference between constant pointer and pointer to a constant.

1220