如何去掉以“.”开头的名字列出文件时

How to elimate names which start with "." when files are listed

我正在尝试通过 C 程序模仿 ls -l 命令 但不幸的是没有得到如何忽略文件之类的 “。” , ".." 和 ".filename" 但不是 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;