我正在学习 C 并且我有这个实现来对文件和文件夹进行排序,但这不区分大小写:
#include <dirent.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
int main(void) {
struct dirent **namelist;
int n;
n = scandir(".", &namelist, NULL, alphasort);
if (n < 0)
perror("scandir");
else {
printf("Inside else, n = %d\n", n);
while (n--) {
printf("%s\n", namelist[n]->d_name);
free(namelist[n]);
}
free(namelist);
}
}
如果我有 a.txt、b.txt、C.txt 和 z.txt,它将按以下顺序排序:C.txt、a.txt、b.txt、z.txt。我希望这样排序不区分大小写:a.txt、b.txt、C.txt、z.txt