I\'m getting a list of files on a linux-like system using opendir/readdir. It appears that the directory entries are returned in alphabetical order of file name. However, I
In addition to the other answers, the readdir man page is pretty clear about files ordering.
The order in which filenames are read by successive calls to readdir() depends on the filesystem implementation; it is unlikely that the names will be sorted in any fashion.
Some file systems, like ReiserFS do list the files in lexical order.
In your case, you have to store the names in an array, then sort the array.
For instance, use qsort() to sort the array.