Program to Reverse a String without using strrev()

Whenever we are asked to reverse a string, we make use of inbuilt function- strrev (). Obviously, it is the easy method and we can use that. But sometimes, we are asked not to use the strrev (). This program helps to reverse a  String without  using strrev().

#include <stdio.h>

#include <conio.h>

#include <string.h> // Mandatory to use if we use string’s inbuilt function , here we have use strlen to find length of string

 Void main()

{

 char string1[10], string2[10];

 int i, length;

 printf(“Enter any string:\n”);

 gets(string1);

 length = strlen(string1)-1;

 for(i=0; string1[i]!=’\0′; i++)

 {

 string2[length]=string1[i];

 length–;

}

 string2[length]=’\0′;

 printf(“\nThe Reverse of string is:\n”);

 puts(string2);

 getch();

}

Mohit Arora
Follow me