#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int compare( const void *arg1, const void *arg2 );
void main( int argc, char **argv )
{
int i;
/* Eliminate argv[0] from sort: */
argv++;
argc--;
/* Sort remaining args using Quicksort algorithm: */
qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare );
/* Output sorted list: */
for( i = 0; i < argc; ++i )
printf( "%s ", argv[i] );
printf( "\n" );
}
int compare( const void *arg1, const void *arg2 )
{
/* Compare all of both strings: */
return _stricmp( * ( char** ) arg1, * ( char** ) arg2 );
}
------------------------------------------------------------------------------------
char cc[10000][256];
qsort((void*)cc,num,sizeof(cc[0]),sort_function);
int sort_function(const void *a,const void *b)
{
cout<<"|"<<(strcmp((char*)a,(char*)b))<<"|";
return(strcmp((char*)a,(char*)b));
}
两种方式的sort_function写法有细微的区别,I DONT KNOW WHY