#include <stdio.h>
#include <stdlib.h>

struct date {
  int year, month, day;
};

struct person {
  char name[20];  /* O */
  struct date birthday; /* a */
  struct person *next;
};

main()
{
  struct person *p, *q;
  int i, y, m, d;
  char s[20];

  p = NULL;
  for (;;) {
    printf("Name: ");
    if (getline(s, 20) == NULL || strcmp(s, "") == 0) break;
    if ((q = malloc(sizeof(struct person))) == NULL) break;
    strcpy(q->name, s);
    printf("Birthday(yyyy mm dd): ");
    getline(s, 20);
    sscanf(s, "%d %d %d", &y, &m, &d);
    q->birthday.year = y;
    q->birthday.month = m;
    q->birthday.day = d;
    q->next = p;
    p = q;
  }
  while (p != NULL) {
    printf("name = %s, birthday = %d %d %d\n", 
      p->name, p->birthday.year, 
      p->birthday.month, p->birthday.day);
    p = p->next;
  }
}
