Used recursion to reverse the string. Another method for string reversal.
String Reversal without using indexing.
#include<stdio.h>
#include<string.h>
char *strrev(char *str)
{
char s[2],*t;
if(strlen(str)==1)
return &str[0];
else
{
s[0]=str[0];
s[1]='\0';
t=strrev((str+1));
strcat(t,s);
return t;
}
}
main()
{
char *str,*dstr;
printf("\n Enter Input string ");
gets(str);
dstr="";
dstr=strrev(str);
printf(" Reverse String %s",dstr);
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
risby 0 Newbie Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.