how can i use qsort to sort alphabetically strings of a 2d array which has strings for a example if i have an array of 4 rows and every row has a string of >=50 characters ...how can i use the qsort function to sort string alphabetically ?
i used this
qsort(arr, i, 500*sizeof(arr[0]), compare);
for (j=0; j<i; j++) {
printf("%s\n",arr[j]);
}
and the comparator i used is
int compare (const void * a, const void * b ) {
return strcmp(a, b);
}
but it gives me segmentation fault error while trying to compile
it gives you a segmentation fault while trying to compile? It sounds like a compiler bug, which is unlikely. You probably encounter it during run time and not compile timereturn strcmp(*(char **)a, *(char **)b);?