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

typedef
struct _people {
  char firstname [50];
  char surname [50];
  char address [100];
  int age;
} people;

void write_person(people person, FILE *fp) {
  fwrite(&person, sizeof(people), 1, fp);
}

void print_person(people person) {

  printf( "First name: %s\n", person.firstname);
  printf( "Surname: %s\n", person.surname);
  printf( "Address: %s\n", person.address);
  printf( "Age: %d\n", person.age);
} //end print_person ()

 
int main()
{
  people person1, person2;
  strcpy(person1.firstname,"John");
  strcpy(person1.surname,"Smith");
  strcpy(person1.address,"123 Main St.");
  person1.age = 32;
  strcpy(person2.firstname,"Dina");
  strcpy(person2.surname,"Hall");
  strcpy(person2.address,"334 High St.");
  person2.age = 29;
  /* print_person(person1); */
  /* print_person(person2); */
  
  FILE *fp;
  fp = fopen("personfile.dat","r");
  if (fp == NULL) {
    fprintf(stderr,"Problem opening file\n");
    exit(1);
  }
  
  /* write_person(person1, fp); */
  /* write_person(person2, fp); */

  while (!feof(fp)) {
    fread(&person1,sizeof(people),1,fp);
    print_person(person1);
  }
  fclose(fp);
}

