Guest User

Untitled

a guest
Feb 21st, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <dirent.h>
  3.  
  4. int main (int argc, char *argv[ ])
  5. {
  6. DIR *dp;
  7. struct dirent *dirp;
  8.  
  9. if (argc != 2) {
  10. fprintf(stderr, "usage: ls directory_name\n");
  11. return 1;
  12. }
  13.  
  14. if ((dp = opendir(argv[1])) == NULL) {
  15. perror("can't copen");
  16. return 2;
  17. }
  18.  
  19. while((dirp = readdir(dp)) != NULL)
  20. printf("%s\n", dirp->d_name);
  21.  
  22. closedir(dp);
  23. return 0;
  24. }
Add Comment
Please, Sign In to add comment