/* ex3 Sorting ints with qsort */Output of Example 3
//
#include <stdio.h>
#include <stdlib.h>
int comp(const int * a,const int * b)
{
if (*a==*b)
return 0;
else
if (*a < *b)
return -1;
else
return 1;
}
int main(int argc, char* argv[])
{
int numbers[10]={1892,45,200,-98,4087,5,-12345,1087,88,-100000};
int i;
/* Sort the array */
qsort(numbers,10,sizeof(int),comp) ;
for (i=0;i<9;i++)
printf("Number = %d\n",numbers[ i ]) ;
return 0;
}
Number = -100000The parameters to qsort are the address of the objects to be sorted, the number of objects, the size of each object and the function that compares two objects.
Number = -12345
Number = -98
Number = 5
Number = 45
Number = 88
Number = 200
Number = 1087
Number = 1892
That completes this lesson on advanced use of pointers. In the next lesson, I'll look at some other advanced data structures.

