Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare(const void *name1, const void *name2)
{
char *const *x = (char *const *)name1;
char *const *y = (char *const *)name2;
return strcmp(*x, *y);
}
int main(void)
{
char *names[] = {"Meg", "John", "Susan", "Charlotte", "Mario"};
int nelements = sizeof(names) / sizeof(*names);
char **p = names;
qsort(names, nelements, sizeof *names, compare);
while (nelements-- > 0)
printf("%s\n", *p++);
return 0;
}
This works perfectly. Now try changing the declarations of x and y in function compare to anything but that...