Here
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* we get here, the equivalent of char** */
/* since qsort effectively calls cmp(&a[x],&a[y]) */
int cmp ( const void *a, const void *b ) {
const char *const *pa = a;
const char *const *pb = b;
return strcmp ( *pa, *pb );
}
void show ( char *arr[], int n ) {
int i;
for ( i = 0 ; i < n ; i++ ) {
printf( "%s\n", arr[i] );
}
printf( "--\n\n" );
}
int main ( ) {
char *test[] = {
"this", "is", "an", "example"
};
show ( test, 4 );
qsort ( test, 4, sizeof test[0], cmp );
show ( test, 4 );
return 0;
}
And please use code tags, not php tags in future.
> strdup() will allocate the required amount of space, copy the string into that memory, and return the pointer.
strdup() is not a standard function.