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

typedef struct person_ {
    // Hmmmm, not good enough to have fixed name sizes
    char first_name[20];
    char family_name[20];
} person ;

int main() {
    person *p;
    person *tmp;

    p = calloc(1, sizeof(person));
    if (p==NULL) {
        fprintf(stderr, "Failed to allocate memory!\n");
        return 1; // indicate errror to user
    }

    /*
     * Give name
     *   I am using two ways of accessing the name variables in the struct
     */
    strcpy((*p).first_name, "Henry");
    strcpy(p->family_name, "Rollins");

    printf("First name:   %s\n", p->first_name);
    printf("Family name:  %s\n", p->family_name);


    /*
       After the print statement in you should add code the uses the function
       realloc to increase (in size) the memory, previously allocated, by
       1. The memory should now be of a size that can store two persons.
    */
    tmp = realloc(p, 2*sizeof(person));
    if (tmp==NULL) {
        fprintf(stderr, "Failed to allocate more memory!\n");
        return 2; // indicate errror to user
    }
    p = tmp;

    strcpy(tmp[1].first_name, "Henry");
    strcpy(tmp[1].family_name, "Rollins");

    printf ("--------------\n");
    printf("First name:   %s\n", p[0].first_name);
    printf("Family name:  %s\n", p[0].family_name);
    printf("First name:   %s\n", p[1].first_name);
    printf("Family name:  %s\n", p[1].family_name);


    free(p);
    return 0;
}
