i2tutorials

Strrev Function

strrev()

 

This function is used to reverse the given string

 

Syntax:

 

strrev(“hello”);
result- olleh­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

 

Example Program:

 

C program to reverse the given string without using string handling function strrev().

 

#include<stdio.h>
#include<string.h>
main()
{
char a[10],b[10];
int n,i,j;
printf("enter string1: ");
gets(a);
printf("before reverse string is: ");
puts(a);
n=strlen(a);
for(i=n-1,j=0;i>=0;i--,j++)
{
b[j]=a[i];
}
b[j]='\0';
printf("string after reverse: ");
printf("%s",b);
}

 

Output:

 

Strrev Function

 

 

Exit mobile version