calculate the length of the string. Copy the characters of the string into another string from the back or in reverse order. We can also use strrev() method to reverse the string. for that, we must include string.h header file.
#include<string.h> int main() { char str[30],rev[30],j,i,l; printf("Enter A String: "); gets(str); l=strlen(str); for(i=0,j=l-1;j>=0;i++,j--) { rev[i]=str[j]; } rev[i]='\0'; printf("Reverse String Is "); puts(rev); return 0; }
#include<string.h> int main() { char str[30],rev[30],j,i,l; printf("Enter A String: "); gets(str); strrev(str); printf("Reverse String Is "); puts(str); return 0; }