#include
#include
#include
int string_comp( const void *sp1, const void *sp2 )
{
const char * s1 = *(char **)sp1;
const char * s2 = *(char **)sp2;
return strcmp( s1, s2 );
}
int main( )
{
char *mots[ ] = { "mal", "rien", "alors", "lui", "programmer",
"tutoriel", "apprendre", "écouter", "lire", "exemple" };
int n = sizeof(mots) / sizeof(char *);
qsort( mots, n, sizeof(char *), string_comp);
for ( int j = 0 ; j < 10 ; j++ )
puts( mots[j] );
return 0;
}
Trier une liste de mot avec ‘qsort()’
Author: user#include
#include
#include
int string_comp( const void *sp1, const void *sp2 )
{
const char * s1 = *(char **)sp1;
const char * s2 = *(char **)sp2;
return strcmp( s1, s2 );
}
int main( )
{
char *mots[ ] = { "mal", "rien", "alors", "lui", "programmer",
"tutoriel", "apprendre", "écouter", "lire", "exemple" };
int n = sizeof(mots) / sizeof(char *);
qsort( mots, n, sizeof(char *), string_comp);
for ( int j = 0 ; j < 10 ; j++ )
puts( mots[j] );
return 0;
}