C program to reverse a string without using strrev() function

Reversing a string is a very common question in basic programming interviews. In this article, we’ll learn how to reverse a string in C without using strrev() function. This C program takes a string as input from the user and then reverses it.

Program: C program to reverse a string without using strrev()

#include <stdio.h>
#include <string.h>
int main()
{
    char myString[50];
    int len, i;
    printf("Enter a string: ");
    fgets(myString, 50, stdin);
    len = strlen(myString);        //strlen() is a function of string.h, it returns the length of the string.
    for(i=len-1; i>=0; i--){
        printf("%c", myString[i]);  
    }
    printf("\n");
    return 0;
}

Output: Reverse string in C without using strrev()

Enter a string: Welcome to the world of computer programming.

.gnimmargorp retupmoc fo dlrow eht ot emocleW

For more programming articles and code snippets, visit programming articles.

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

Your email address will not be published. Required fields are marked *