converting .c file to .o using processes

  .a, c++, gcc

I have to make a project which asks me to create a program that will compile a C project by recursively descending into directories and launching processes which compile a file of code by calling GCC and look through directories and launch a new process for every “.c” file in the current directory that process will call gcc on the .c file making a .o file.

I have written this code so far to list the directories first
I am having trouble checking what files are .c and how to convert them to .o

can someone help me with some relevant information/links that I can refer to? 

void listdir(const char *name, int indent)
    DIR *dir;
    struct dirent *entry;

    if (!(dir = opendir(name)))

    while ((entry = readdir(dir)) != NULL) {
        if (entry->d_type == DT_DIR) {
            char path[1024];
            if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
            snprintf(path, sizeof(path), "%s/%s", name, entry->d_name);
            printf("%*s[%s]n", indent, "", entry->d_name);
            listdir(path, indent + 2);
        } else {
            printf("%*s- %sn", indent, "", entry->d_name);

int main(void) {
    listdir(".", 0);
    return 0;

Source: StackOverflow C++