This is the solution of Programming Pearls in column 1.6_1:
> #include <stdio.h>
int intcomp(int *x, int *y)
{
return *x-*y;
}
int a[1000000];
int main(void) {
// insert code here...
int i,n=0;
while (scanf("%d",&a[n])!=EOF) {
n++;
}
qsort(a,n,sizeof(a[0]),intcomp);
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
return 0;
}
Error message:
conflicting types for "qsort"
Can you tell me why could that happen? Isn't it defined by default?
My compiler is Xcode (MacOS).
Comment (which turned out to be a correct guess) promoted to answer:
It's unclear if the source code above was from typed in from the book, or found online. The code above has a few differences from this github copy of p1c1quicksort, i.e. the code above is missing:
#include <stdlib.h>.