fork download
  1. #include <stdio.h>
  2. #include <dirent.h>
  3.  
  4. int main()
  5. {
  6. DIR *dir;
  7. struct dirent *entry;
  8.  
  9. dir = opendir(".");
  10. if (dir == NULL)
  11. {
  12. printf("Directory cannot be opened\n");
  13. return 1;
  14. }
  15.  
  16. printf("Files in directory:\n");
  17.  
  18. while ((entry = readdir(dir)) != NULL)
  19. {
  20. printf("%s\n", entry->d_name);
  21. }
  22.  
  23. closedir(dir);
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Files in directory:
..
prog
.