Advertisement
Guest User

Untitled

a guest
May 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. char** folderFiles(char* folder, int* numOfFiles)
  2. {
  3. char** fileNames = NULL;
  4. DIR *dp;
  5. struct dirent *ep;
  6. dp = opendir(folder);
  7. int i = 0;
  8. fileNames = (char**)malloc(sizeof(char*));
  9. if (dp != NULL)
  10. {
  11. while (ep = readdir(dp))
  12. {
  13. if (i >= 2)
  14. {
  15. *numOfFiles = *numOfFiles + 1;
  16. fileNames=(char**)realloc(fileNames, *numOfFiles);
  17. *(fileNames + i - 2) = (char*)malloc((strlen(ep->d_name)+1)*sizeof(char));
  18. strcpy(*(fileNames + i - 2), ep->d_name);
  19. printf("%p %d", *(fileNames + i - 2),i);
  20. printf("%p %d", *(fileNames + 2 - 2), 2);
  21. printf("%s\n", *(fileNames + i - 2));
  22. }
  23. i++;
  24. }
  25. printf("%p %d\n", *(fileNames + 2 - 2), 2);
  26. (void)closedir(dp);
  27.  
  28. }
  29. else
  30. perror("Couldn't open the directory");
  31. return fileNames;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement