linux c 排序函数,alphasort - Linux C 函数 使用手册

本文介绍了用于按字母顺序对目录结构进行排序的alphasort函数。该函数作为scandir和qsort的一部分,在读取目录内容后对其进行排序。示例代码展示了如何使用这些函数来列出并按字母顺序排列目录项。

alphasort(依字母顺序排序目录结构)

相关函数 scandir,qsort

表头文件 #include

定义函数 int alphasort(const struct dirent **a,const struct dirent

**b);

函数说明 alphasort()为scandir()最后调用qsort()函数时传给qsort()作为

判断的函数,详细说明请参考scandir()及qsort()。

返回值 参考qsort()。

范例:

/* 读取/目录下所有的目录结构,并依字母顺序排列*/

main()

{

struct dirent **namelist;

int i,total;

total = scandir(“/”,&namelist ,0,alphasort);

if(total <0)

perror(“scandir”);

else{

for(i=0;i

printf(“%s\n”,namelist[i]->d_name);

printf(“total = %d\n”,total);

}

}

执行 ..

.gnome

.gnome_private

ErrorLog

Weblog

bin

boot

dev

dosc

dosd

etc

home

lib

lost+found

misc

mnt

opt

proc

root

sbin

tmp

usr

var

total = 24

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值