2005-03-15 Jakub Jelinek <jakub@redhat.com>
[glibc/history.git] / stdlib / testsort.c
blobaa4332a5686f8f4813736f3ce858292105aa4f27
1 #include <stdlib.h>
2 #include <string.h>
3 #include <stdio.h>
5 static int
6 compare (const void *a, const void *b)
8 return strcmp (*(char **) a, *(char **) b);
11 int
12 main (void)
14 char bufs[500][20];
15 char *lines[500];
16 size_t lens[500];
17 size_t i, j;
19 srandom (1);
21 for (i = 0; i < 500; ++i)
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';
30 qsort (lines, 500, sizeof (char *), compare);
32 for (i = 0; i < 500 && lines[i] != NULL; ++i)
33 puts (lines[i]);
35 return 0;