Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdlib.h>
    void qsort( void *base,
                size_t num,
                size_t width,
                int (*compar)
                     ( const void *, const void *) );

Description:
    The  qsort function sorts an array of num elements, which is pointed to
    by base, using Hoare's Quicksort algorithm.  Each element in the array
    is width bytes in size.  The comparison function pointed to by compar is
    called with two arguments that point to elements in the array.  The
    comparison function shall 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.

Returns:
    The  qsort function returns no value.

See Also:
    bsearch

Example:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    char *CharVect[] = { "last", "middle", "first" };

    int compare( const void *op1, const void *op2 )
      {
        const char **p1 = (const char **) op1;
        const char **p2 = (const char **) op2;
        return( strcmp( *p1, *p2 ) );
      }

    void main()
      {
        qsort( CharVect, sizeof(CharVect)/sizeof(char *),
              sizeof(char *), compare );
        printf( "%s %s %s\n",
                CharVect[0], CharVect[1], CharVect[2] );
      }

    produces the following:

    first last middle

Classification:
    ANSI

Systems:
    All

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson