Re: [cpp] 在标准C中用qsort来给字符串排序, 怎么写compare函数啊?

Stone Jiang 2005119 at gmail.com
Mon Jul 10 16:13:33 CST 2006


/* qsort example */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* values[] = { "40", "10", "100", "90", "20", "25" };

int compare (const void * a, const void * b)
{


	return ( strcmp(*(char**)a,*(char**)b));
}

int main ()
{
	
	int n;
	qsort (values, sizeof values /sizeof values[0],sizeof(values[0]), compare);
	for (n=0; n<6; n++)
	{
		printf ("%s ",values[n]);
	}
	return 0;
}


On 7/9/06, heron <toqz at 163.com> wrote:
> 很弱智的一个问题, 谢谢大家
>
>
>
>> 礼!
>
> Best Regards!
> heron
> toqz at 163.com
> 2006-07-09
>
> _______________________________________________
> Cpp mailing list
> Cpp at codingnow.com
> http://codingnow.com/mailman/listinfo/cpp
>


-- 
Take care
Stone Jiang
blog:  http://blog.csdn.net/FocusOnACE/



More information about the Cpp mailing list