我在制作递归目录列表器时遇到的问题之一是在递归函数的堆栈中没有调用目录检查后的调用。
void direct_crawl(int indent, char *cwd, STAT nstat)
{
int i, i_in, count;
struct direct **files;
int file_comp();
count = scandir(cwd, &files, file_comp, alphasort);
for (i = 0; i < count; i++)
{
for (i_in = 0; i_in < indent; i_in++)
printf("\t");
printf("%s\n", files[i]->d_name);
stat(files[i], nstat);
if (S_ISDIR(nstat->st_mode) != 0)
direct_crawl(indent + 1, files[i]->d_name, nstat)
}
}
它上升了一个子目录,但如果这些目录有子目录,它就不会打扰......所以,有人可以解释一下我做错了什么吗?谢谢。