qsort

Sorts an array of elements.

Library:LibC
Classification:ANSI
Service:General C Services

Syntax

  #include <stdlib.h> 
   
  void qsort (
     void    *base,   
     size_t   num,   
     size_t   width,   
     int    (*compar) (
        const void *elem1, 
        const void *elem2));
  

Parameters

base

(IN) Points to the array to sort.

num

(IN) Specifies the number of elements in the array.

width

(IN) Specifies the size (in bytes) of each element in the array.

compar

(IN) Points to the comparison function.

elem1

(IN) Points to the first element to compare.

elem2

(IN) Points to the second element to compare.

Remarks

The qsort function sorts an array of elements (pointed to by the base parameter) using the comparison function that you supply.

The comparison function pointed to by the compar parameter is called with two arguments that point to elements in the array. The comparison function will return an integer less than, equal to, or greater than zero if the first argument is less than, equal to, or greater than the second argument.

The size of each element in the array is the number of bytes specified by the width parameter.

See Also

bsearch