CS140 -- Midterm Exam: Q12 - Q14

The following code is for questions 12 through 14


typedef struct {
  char *firstname;
  char *lastname;
  int age;
} Person;

Suppose we want to read ten ``persons'' into an array. We know that standard input will contain 10 lines, each line being of the form:
firstname lastname age
We write a driver routine as follows:
#include "fields.h"

main()
{
  Person **p;
  IS is;

  p = (Person **) malloc(sizeof(Person *)*10);
  is = new_inputstruct(NULL);

  for (i = 0; i < 10; i++) {
    get_line(is);
    p[i] = make_new_person(is);
  }

  ...
}
Now, here is a skeleton of make_new_person(). Your job will be to fill in the ``code fragments.''
Person *make_new_person(IS is)
{
  Person *p;
  Person p2;
  Person parray[1];

  /* Code Fragment 1: Initialize p */

  /* Code Fragment 2: Initialize firstname and lastname */

  /* Code Fragment 3: Initialize age */

  return p;
}