Program to Reverse the String Using Function and Array

This is the simple program to reverse a string using function and array in c.

Program to Reverse the String Using Function and array

Source Code:

// program to reverse the string using function and array 
#include <stdio.h>
#include <stdlib.h>

// revese string function body
void revStr(char rstr[40]){
    int i, j = 10;
    char arr[40];

    // for loop for reverse string 
    for(i = 0; i <= 10; i++){
        arr[j] = rstr[i];
        j--;
    }

    //printing the reverse string 
    printf("Revese string is: %s \n" , arr);
}

// main function
void main(){

    // string for reverse
    char str[40] = "techalmirah";
    char arr[40];

    //print old string
    printf("String is: %s \n" , str);

    //calling reverse string function 
    revStr(str);
}

Output:

String is: techalmirah 
Revese string is: harimlahcet
Posted in: C