strrev() Reversing a string

We can use string function strrev() to reverse a string.
strlen(strrev);

Example using strrev()

#include<stdio.h>
#include<string.h>

int main()
{
   char str[30] = "plus2net";
   printf("String after reverse  : %s",strrev(str));
   return 0;
}
The output of above code is here
ten2sulp

Example 2

#include<stdio.h>
#include<string.h>

int main()
{
   char str[30] = "plus2net";
   strcpy(str,strrev(str));
   printf("String after reverse  : %s",str);
   return 0;
}

Example Using one input string

#include<stdio.h>
#include<string.h>

int main()
{
 char str[30];
   printf("Enter a string   ");
	scanf("%s",str);
   strcpy(str,strrev(str));
   printf("String after reverse  : %s",str);
   return 0;
}

Printing in reverse order without using strrev()

#include<stdio.h>
#include<string.h>

int main()
{
 char str[30]="plus2net";
 int str_length;
 str_length=strlen(str); // length of the string
 for(int i=str_length; i>=0; i--){
 printf("%c",str[i]);   // printing the char at position  i
 }
return 0;
}
Your Rating




Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer