2024年4月14日发(作者:)
C语言alphasort()函数:依字母顺序排序目录结构
相关函数:scandir, qsort
头文件:#include
定义函数:int alphasort(const struct dirent **a, const struct dirent **b);
函数说明:alphasort()为scandir()最后调用qsort()函数时传给qsort()作为判断的函
数, 详细说明请参考scandir()及qsort().
返回值参考qsort()。
范例
/* 读取/目录下所有的目录结构, 并依字母顺序排列 */
#include
main()
{
struct dirent **namelist;
int i, total;
total = scandir("/", &namelist, 0, alphasort);
if(total < 0)
perror("scandir");
else
{
for(i = 0; i < total; i++)
printf("%sn", namelist[i]->d_name);
printf("total = %dn", total);
}
}
执行:
..
.gnome


发布评论