q.txt
Upload User: harvey99
Upload Date: 2020-01-11
Package Size: 938k
Code Size: 1k
Category:

Other Books

Development Platform:

CHM

  1. 函数名: qsort
  2. 功  能: 使用快速排序例程进行排序
  3. 用  法: void qsort(void *base, int nelem, int width, int (*fcmp)());
  4. 程序例: 
  5. #include <stdio.h>
  6. #include <stdlib.h> 
  7. #include <string.h>
  8. int sort_function( const void *a, const void *b);
  9. char list[5][4] = { "cat", "car", "cab", "cap", "can" };
  10.  
  11. int main(void)
  12. {
  13.    int  x;
  14.    qsort((void *)list, 5, sizeof(list[0]), sort_function);
  15.    for (x = 0; x < 5; x++)
  16.       printf("%sn", list[x]);
  17.    return 0;
  18. }
  19. int sort_function( const void *a, const void *b)
  20. {
  21.    return( strcmp(a,b) );
  22. }