Reverse a String without using strrev (Pointer Approach) in C

C Program to reverse a String without using strrev (Pointer Approach)

Source code :

#include <stdio.h>
#include <string.h>
#include <malloc.h>

int main(){
    
    char *original = "LOVE";
    int length = strlen(original);
    char *reversed = malloc( length * sizeof(char));
    int i,j=0;
    
    for( i = length - 1 ; i >= 0 ; i-- ){
        reversed[i] = original[j];
        j++;
    }
    
    printf("Original String : %s", original);
    printf("\nReversed String : %s", reversed);

    return 0;

}

Output :

Original String : LOVE
Reversed String : EVOL

Output :


                

Comments :