M
monkeys paw
Compiling the following code gives me this warning:
headsort.c: In function `main':
headsort.c:22: warning: passing arg 4 of `qsort' from incompatible
pointer type
Anyone know why??
Code:
int strcompare(void *p1, void *p2) {
return strcmp((char *)p1, (char *)p2);
}
int main()
{
char *ary[] = { "abc", "zyx", "qrt", "123", "cba", "mud"};
size_t nelems, i;
nelems = sizeof(ary) / sizeof(char *);
printf("%d\n", nelems);
qsort((void *)ary, (size_t)nelems, sizeof(ary[0]), strcompare);
printf("\nSorted list:");
for (i=0; i<nelems; i++) {
printf(" %s ", ary);
}
headsort.c: In function `main':
headsort.c:22: warning: passing arg 4 of `qsort' from incompatible
pointer type
Anyone know why??
Code:
int strcompare(void *p1, void *p2) {
return strcmp((char *)p1, (char *)p2);
}
int main()
{
char *ary[] = { "abc", "zyx", "qrt", "123", "cba", "mud"};
size_t nelems, i;
nelems = sizeof(ary) / sizeof(char *);
printf("%d\n", nelems);
qsort((void *)ary, (size_t)nelems, sizeof(ary[0]), strcompare);
printf("\nSorted list:");
for (i=0; i<nelems; i++) {
printf(" %s ", ary);
}