Reverse a string - C Program

Write a C program to accept a string from user and reverse it.

Solution:

#include<stdio.h>
#include<string.h>
int main()
{
    /* Here, we decalre s[120]. Hence, you can enter maximum 120 character in string*/
    char s[120], t;
    int i=0, j = 0;
    printf("Enter String : ");
    gets(s);   
    j = strlen(s) - 1;
    while (i < j)
    {
        t = s[i];
        s[i] = s[j];
        s[j] = t;
        i++;
        j--;
    }
    printf("\nReverse String = %s", s);
    return (0);
}


Output:

reverse string