using qsort to sort an array of long long int not working for large nos

c, qsort

Solution

The result of `compare` function must be `int`. The subtraction of two `long long` can easily overflow the `int` type (and it does in your case).

Try comparing the two values explicitly and returning -1, 0 or 1.

Problem

I am using this compare function to sort an array consisting of long long int nos. ``` int compare(const void * p1,const void * p2) { return (* (long long int * )a-*(long long int * )b); } qsort(array,no of elements,sizeof(long long int),compare) ``` this works fine for small nos but when the array contains nos of the oreder of 10^10 it gives wrong results? what is the mistake i am making?

Original source