>>22 (2)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum { NC_MAX = 10, NLEN = 10 };
int cmp(const void *a, const void *b) {
  return strcmp(*(char**)a, *(char**)b);
}
char *strndup(const char *s, size_t n) {
  char *ss;
  size_t len = strlen(s);
  if (len < n) n = len;
  ss = malloc(n + 1);
  return strncat(ss, s, n);
}
int main(void) {
  char *p, *names[NC_MAX] = { 0 }, buff[BUFSIZ];
  int i, nc;
  for (nc = 0; nc < NC_MAX; ) {
    fputs("name => ", stdout);
    if (!fgets(buff, sizeof buff, stdin) || buff[0] == '0') break;
    if ((p = strchr(buff, '\n'))) *p = '\0';
    names[nc++] = strndup(buff, NLEN);
    printf("累計%d件\n", nc);
  }
  qsort(names, nc, sizeof(char*), cmp);
  for (i = 0; i < nc; ++i) {
    printf("%d:%s\n", i + 1, names[i]);
    free(names[i]);
  }
  return 0;
}