String Reverse in C Program Example

How to write a c program to reverse a string in c programming ?

Solution:
#include <stdio.h>
#include <string.h>

void stringReverse(char str1[]);

int main()
{
    char s1[] = "BUET";

    stringReverse(s1);

    printf(s1);

    return 0;
}

void stringReverse(char str[])
{
    char temp[100];
    int len = strlen(str), i;

    for(i = 0; str[i] != '\0'; i++)
        temp[len - i - 1] = str[i];
    temp[i] = '\0';

    strcpy(str, temp);
}


Learn More :