C Programming Code Examples C > Strings Code Examples Program to find reverse of a string using strrev() function Program to find reverse of a string using strrev() function Write a C program to find reverse of a given string using loop. How to find reverse of any given string using loop in C programming. Logic to find reverse of a string without using strrev() function in C. C program to reverse a string using strrev() string function. Logic to find reverse of a string There are numerous ways to find reverse of a string. Here in this lesson I am going to explain few of them. First let us see the easiest method to find reverse of a string. Input a string from user, store it in some variable say str. Declare another array that will store reverse of the string, say char reverse[SIZE]. Find length of the string and store it in some variable say len. Initialize two variables that will keep track of original and reverse string. Here we will access original string from last and reverse array from first. Hence, initialize strIndex = len - 1 and revIndex = 0. Run a loop from len - 1 to 0 in decremented style. The loop structure should look like while(strIndex >= 0). Inside the loop copy current character from original string to reverse string. Say reverse[revIndex] = str[strIndex];. After copying, increment revIndex and decrement strIndex. #include <stdio.h> #include <string.h> #define maxsize 100 // Maximum string size int main() { char str[maxsize]; /* Input string from user */ printf("Enter any string: "); gets(str); printf("Original string = %s\n", str); /* Find the reverse of string */ strrev(str); printf("Reverse string = %s", str); return 0; }