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

Give differences between - new and malloc() , delete and free() ?

1105


Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

1056


Explain how can you avoid including a header more than once?

1099


how can f be used for both float and double arguments in printf? Are not they different types?

1079


Why isn't any of this standardized in c? Any real program has to do some of these things.

1225


What does typedef struct mean?

1119


What is the purpose of type declarations?

1122


When should volatile modifier be used?

1023


C language questions for civil engineering

1724


What is the purpose of ftell?

1091


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3697


what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)

2418


provide an example of the Group by clause, when would you use this clause

2201


What is the return type of sizeof?

1067


What is function definition in c?

1085