(root)/
glibc-2.38/
stdlib/
testsort.c
       1  #include <stdlib.h>
       2  #include <string.h>
       3  #include <stdio.h>
       4  
       5  static int
       6  compare (const void *a, const void *b)
       7  {
       8    return strcmp (*(char **) a, *(char **) b);
       9  }
      10  
      11  int
      12  main (void)
      13  {
      14    char bufs[500][20];
      15    char *lines[500];
      16    size_t lens[500];
      17    size_t i, j;
      18  
      19    srandom (1);
      20  
      21    for (i = 0; i < 500; ++i)
      22      {
      23        lens[i] = random() % 19;
      24        lines[i] = bufs[i];
      25        for (j = 0; j < lens[i]; ++j)
      26  	lines[i][j] = random() % 26 + 'a';
      27        lines[i][j] = '\0';
      28      }
      29  
      30    qsort (lines, 500, sizeof (char *), compare);
      31  
      32    for (i = 0; i < 500 && lines[i] != NULL; ++i)
      33      puts (lines[i]);
      34  
      35    return 0;
      36  }