program to reverse a string using recursive function:
---------------------------------------------------
void reverse (int index char *str ) ;
int main (void)
{
char name[100];
printf ( Enter a mutli-word string ) ;
gets(name) ;
reverse (strlen(name) name ) ;
}
void reverse (int index char *str )
{
if (--index < 0 )
{
return ;
}
else
{
putchar ( *(str + index) ) ;
reverse (index str) ;
}
}
Logic:
-----
For eg : let's say the user has entered 50 characters.
then index is initially 50.
when reverse() function is called for the first time then
index will be 50 .we first decrement the index by 1 so that
it will become 49 and i am printing the 49th character i.e last
character in the string then reverse() function is called again
with index as 49 and str pointing to 49th character and again
the index will be decremented by 1 so that it will become 48 this
will continue until zeroth index is reached.
i hope this will solve the problem that you have reported for any
queries you can mail me.
Regards
Syed