0

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).

4

1 回答 1

0

评论(结果证明是正确的猜测)提升为回答:

目前还不清楚上面的源代码是从书中输入的,还是在网上找到的。上面的代码与 p1c1quicksort 的这个 github 副本有一些不同,即上面的代码丢失了:

#include <stdlib.h>. 
于 2016-07-02T20:42:17.033 回答