Search in shivacherukuri.tech@blogger.com

Thursday, March 18, 2010

Rreverse of string without using extra memory or swaping



/* Following code does as intended */
#include <stdio.h>
 
#define REVERSE_STRING(X) Rstring(X, *(X), strlen(X)-1)
 
void Rstring( char *str, char c, int index )
{
        if( index != 0 )
               Rstring( str, *(str+(strlen(str))-index),
index-1);     
        *(str+index) = c;             
}
 
int main( void )
{
        char str[] = "Dharmendra Patel";
        printf("Actual string is [%s]\n", str);
        REVERSE_STRING(str);
        printf("Reversed string is [%s]\n", str);
        return 0;
}


No comments:

Post a Comment