我必须创建一个项目,要求我创建一个程序,该程序将通过递归地进入目录并启动进程来编译C项目,该进程通过调用GCC并浏览目录并为每个“ .c”启动新进程。当前目录中的文件,该进程将在.c文件上调用gcc,从而生成.o文件。
到目前为止,我已经编写了此代码以首先列出目录 我在检查什么文件是.c以及如何将它们转换为.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)))
return;
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)
continue;
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- %s\n", indent, "", entry->d_name);
}
}
closedir(dir);
}
int main(void) {
listdir(".", 0);
return 0;
}