#include <stdio.h>
#include <string.h>
int main()
{
int i,j,len=0;
char str[50],revstr[50];
printf("\n Enter a String to Reverse : " );
// Use fgets to read input, with a maximum size of 50 characters
fgets(str, sizeof(str), stdin);
// Remove the newline character from the end of the string
str[strcspn(str, "\r\n")] = 0;
// Count the length of the string
for(i=0; str[i]!='\0'; i++)
{
len++;
}
j=0;
// Reverse the string by copying each character from the original string to the new string in reverse order
for(i=len-1; i>=0; i--)
{
revstr[j++]=str[i];
}
printf("\n Reverse of the Given String is: %s",revstr);
return 0;
}
OUTPUT:
Enter a String to Reverse : www.programming9.com Reverse of the Given String is: moc.9gnimmargorp.www