qsort function


qsort will sort an array of elements. This is a wild function that uses a pointer to another function that performs the required comparisons.

Library:   stdlib.h

Prototype: void qsort(void *base, 
		      size_t num, 
		      size_t size, 
 		      int (*comp_func)(const void *, const void *))


Some explanation.


Notes

  1. Well... This caused me alot of trouble! Although the prototype above is exactly as shown in the documentation, the last parm kept giving compiler warnings (invalid pointer type) this is the fix.
    	
    Prototype: void qsort(void *base, 
    		      size_t num, 
    		      size_t size, 
     		      (void *) (*comp_func)(const void *, const void *))
    
    does anyone know the answer to this problem??

  2. I think void * needs an explanation.

  3. And cast aswell


Example program 1 As basic as I can make it.

Example program with user input.

O'Reilly 'Using C' example.


Top Master Index Keywords Functions


Martin Leslie