#include <stdio.h> #include <sys/types.h> #include <fcntl.h> #include <dirent.h> #include <stdlib.h> int main() { char dname[100]; DIR *p; struct dirent *d; printf("Enter directory name: "); scanf("%s", dname); p = opendir(dname); if (p == NULL) { perror("Cannot open directory"); exit(EXIT_FAILURE); } while ((d = readdir(p)) != NULL) { printf("%s\n", d->d_name); } closedir(p); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter