strrev() function in string by R4R Team

-Here we try to reverse the string and store in another string.

Example-
string is "HEY"
reverse is :"YEH"

program-

#include< stdio.h>
#include< string.h>
int main()
{
char s[20],s1[20];
int i=0,len=0;
//input of string
printf("Enter string\n");
scanf("%s",&s);
while(s[i++]!='')
len++;
i=0;
while(s[i]!='')
{
s1[i]=s[len-i-1];
i++;
}
s1[i]='';
printf("String in reverse order is %s",s1);
}


output-

Enter string
Mystring
String in reverse order is gnirtsyM

-In this program, we take an input of the string and try to reverse it.
-Firstly find the length of the string.
-Then traverse string in reverse order and store each character in second string.
-At last display that string.




Leave a Comment: