One tiny addition to JB Jansen's answer - in the main readdir()
loop I'd add this:
if (dir->d_type == DT_REG)
{
printf("%s\n", dir->d_name);
}
Just checking if it's really file, not (sym)link, directory, or whatever.
NOTE: more about struct dirent
in libc
documentation.