c语言 - 列出文件时如何消除以"."开头的名称



我正试图通过c程序模拟ls-l命令但不幸的是,我不知道如何忽略以下文件&"&"quot;和";。文件名";但不是filename.c我设法找到了。在文件名中并忽略,但后来意识到我甚至丢失了filename.c

急性含量为

.
..
.bitfile
.gnupg
krishna
program.c
temp

现在我的代码是

while ((dir = readdir(d)) != NULL)
{
if (strstr(dir->d_name, ".") != NULL || strstr(dir->d_name, "..") != NULL)
continue; 
strcpy(array[i], dir->d_name);
i++;
}

阵列中的内容为:

krishna
temp

但预期产量为

krishna
program.c
temp

为什么不简单地:

if (dir->d_name[0] == '.') continue;

最新更新