How to qsort a dirent in C
问题 Brand new to C and finding it confusing. What I really want to know about, is taking two separate pieces of code and getting them to work together. Here's some code that simply lists the contents of the current directory: #include <stdio.h> #include <sys/types.h> #include <dirent.h> int main (void) { DIR *dp; struct dirent *ep; dp = opendir ("./"); if (dp != NULL) { while (ep = readdir (dp)) puts (ep->d_name); (void) closedir (dp); } else perror ("Couldn't open the directory"); return 0; }