C Example | Reverse a String

This c example code shows us how to reverse a string correctly.

#include<stdio.h>
#include<string.h>
int main()
{
   char str[100];
   printf("Enter string: ");
   fgets(str, sizeof(str), stdin);

   strrev(str);
   printf("The reverse of the string is: ");
   puts(str);

   return 0;
}

Run this code, we wil get:

Enter string: Programming
The reverse of the string is:
gnimmargorP