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 / ozzy

#include <stdio.h>
#include <string.h>

int recreverse (char szStr[], int nSize, int i)
{
// printf ("\n %d - %s ", i, szStr);

if (i < nSize /2)
{
szStr[i] ^= szStr[nSize -(i + 1)];
szStr[nSize -(i + 1)] ^= szStr[i];
szStr[i] ^= szStr[nSize -(i + 1)];

recreverse (szStr, nSize, ++i);
}
else
return;



}

int main()
{
char szStr[256];
int nSize,i;
char cChar;
// int nHash[26] = {0};
// char szDict[26] ="abcdefghijklmnopqrstuvwxyz";

printf("\n Enter the character : ");
// scanf("%s,", szStr);
gets(szStr);
nSize = strlen (szStr);
printf ("\n string %s - %d \n", szStr, nSize);

recreverse (szStr, nSize, 0);


printf ("\n Reverse <<%s>> \n", szStr);

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is there a way to compare two structure variables?

1080


What is the difference between single charater constant and string constant?

1052


What is boolean in c?

1047


What is the difference between char array and char pointer?

1006


What does a pointer variable always consist of?

1057


What does stand for?

1052


how can use subset in c program and give more example

1951


What are the advantages of using Unions?

1081


What is the difference between %d and %i?

1062


Can you please explain the difference between strcpy() and memcpy() function?

1029


What does %c do in c?

949


What is the difference between abs() and fabs() functions?

1078


How to delete a node from linked list w/o using collectons?

2741


What is c mainly used for?

1012


Write a code to determine the total number of stops an elevator would take to serve N number of people.

1215