How to list all files in the directory in C language

How to list all files in the directory in C language

search the current directory and print out all files

/*
Example:list all files in a specified directory using C language
*/

#include <dirent.h>
#include <stdio.h>

int main(void) {
  DIR *d;
  struct dirent *dir;
  d = opendir(".");
  if (d) {
    while ((dir = readdir(d)) != NULL) {
      printf("%s\n", dir->d_name);
    }
    closedir(d);
  }
  return(0);
}
So‮ru‬ce:www.lautturi.com
Created Time:2017-08-29 05:08:37  Author:lautturi