#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
We can use string function strrev() to reverse a string.
strlen(strrev);
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;
}