Back to index

glibc  2.9
tst-svc.c
Go to the documentation of this file.
00001 /* Test for strverscmp() */
00002 
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #include <string.h>
00006 
00007 #define  MAX_STRINGS      256
00008 #define  MAX_LINE_SIZE    32
00009 
00010 static int
00011 compare (const void *p1, const void *p2)
00012 {
00013   return strverscmp (*((char **) p1), *((char **) p2));
00014 }
00015 
00016 int
00017 main (int argc, char *argv[])
00018 {
00019   char line[MAX_LINE_SIZE + 1];
00020   char *str[MAX_STRINGS];
00021   int  count = 0;
00022   int  i, n;
00023 
00024   while (count < MAX_STRINGS && fgets (line, MAX_LINE_SIZE, stdin) != NULL)
00025     {
00026       n = strlen (line) - 1;
00027 
00028       if (line[n] == '\n')
00029         line[n] = '\0';
00030 
00031       str[count] = strdup (line);
00032 
00033       if (str[count] == NULL)
00034         exit (EXIT_FAILURE);
00035 
00036       ++count;
00037     }
00038 
00039   qsort (str, count, sizeof (char *), compare);
00040 
00041   for (i = 0; i < count; ++i)
00042     puts (str[i]);
00043 
00044   return EXIT_SUCCESS;
00045 }