bash convert find to array

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

int main() {
    FILE *fp = popen("find /path/to/search -type f", "r");
    if (fp == NULL) {
        printf("Failed to run command\n");
        exit(1);
    }

    char buffer[1024];
    int count = 0;
    char *files[100]; // Assuming a maximum of 100 files

    while (fgets(buffer, sizeof(buffer), fp) != NULL) {
        buffer[strcspn(buffer, "\n")] = 0; // Remove the newline character
        files[count] = strdup(buffer);
        count++;
    }

    pclose(fp);

    // Printing the files in the array
    for (int i = 0; i < count; i++) {
        printf("%s\n", files[i]);
        free(files[i]); // Freeing the memory allocated by strdup
    }

    return 0;
}