Back to index

glibc  2.9
Defines | Functions
tst-svc.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Defines

#define MAX_STRINGS   256
#define MAX_LINE_SIZE   32

Functions

static int compare (const void *p1, const void *p2)
int main (int argc, char *argv[])

Define Documentation

#define MAX_LINE_SIZE   32

Definition at line 8 of file tst-svc.c.

#define MAX_STRINGS   256

Definition at line 7 of file tst-svc.c.


Function Documentation

static int compare ( const void *  p1,
const void *  p2 
) [static]

Definition at line 11 of file tst-svc.c.

{
  return strverscmp (*((char **) p1), *((char **) p2));
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 17 of file tst-svc.c.

{
  char line[MAX_LINE_SIZE + 1];
  char *str[MAX_STRINGS];
  int  count = 0;
  int  i, n;

  while (count < MAX_STRINGS && fgets (line, MAX_LINE_SIZE, stdin) != NULL)
    {
      n = strlen (line) - 1;

      if (line[n] == '\n')
        line[n] = '\0';

      str[count] = strdup (line);

      if (str[count] == NULL)
        exit (EXIT_FAILURE);

      ++count;
    }

  qsort (str, count, sizeof (char *), compare);

  for (i = 0; i < count; ++i)
    puts (str[i]);

  return EXIT_SUCCESS;
}

Here is the call graph for this function: