Alex.
Retired
- Joined
- Aug 24, 2005
- Messages
- 4,616
Hi,
I've been having some trouble with a small file browser that looks for a specific type of files in a predefined folder. In order for things to make sense, I want to read the files in alphabetical order. Here's the code:
CODE
#include <dirent.h>
#include <sys/unistd.h>
extern int alphasort();
..
struct dirent** fileList;
int n = scandir(MAP_DIR, &fileList, NULL, alphasort);
for(i = 0; i < n; i++) {
// add fileList->d_name to a string linked list
}
The problem is that sometimes the files are read in proper alphabetical order, sometimes in reverse alphabetical order, and sometimes in a seemingly random manner. Sorry to ask such simple things, but I really lack experience in this part. Thanks a lot
I've been having some trouble with a small file browser that looks for a specific type of files in a predefined folder. In order for things to make sense, I want to read the files in alphabetical order. Here's the code:
CODE
#include <dirent.h>
#include <sys/unistd.h>
extern int alphasort();
..
struct dirent** fileList;
int n = scandir(MAP_DIR, &fileList, NULL, alphasort);
for(i = 0; i < n; i++) {
// add fileList->d_name to a string linked list
}
The problem is that sometimes the files are read in proper alphabetical order, sometimes in reverse alphabetical order, and sometimes in a seemingly random manner. Sorry to ask such simple things, but I really lack experience in this part. Thanks a lot