I've just started learning about divide and conquer and I'm trying to write a program that displays the longest common prefix from a list of strings.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const char *lcpUtil(char str1[], char str2[])
{
    char *result = malloc(sizeof(char) * 100);
    result = "";
    int n1 = strlen(str1), n2 = strlen(str2);
    
    for(int i = 0, j = 0; i <= n1-1 && j <= n2-1; i++, j++)
    {
        if(str1[i] != str2[j])
            break;
        strncat(result, &str1[i], 1); // append the prefix to the result string
    } 
    
    return (result);
}
const char *lcp(char **str, int l, int r)
{
    char str1[100], str2[100];
    if (l < r)
    {
        int m = (l + r)/2;
        
        strcpy(str1, lcp(str, l, r));
        strcpy(str2, lcp(str, m+1, r));
    }
    return (lcpUtil(str1, str2));
}
int main(int argc, char **argv)
{
    char *arr[4] = {"apple", "application", "april", "apartment"}; // ap
    int n = 4;
    char prefix[100];
    strcpy(prefix, lcp(arr, 0 , n-1));
    if(strlen(prefix))
    {
        printf("The longest common prefix: %s\n", prefix);
    }
    else
        printf("There is no common prefix");
    return 0;
}
Right now, I'm getting a segmentation and I'm not certain why.
 
    