/* Filename:  reademp.cpp

   Author:  Br. David Carlson

   Date:  February 4, 1998

   Last Revised:  November 23, 2001

   This program reads the emp.dat binary file of employee records, as
   created by the makeemp program.  The data for the records is displayed
   on the screen.

   Tested with:
      Microsoft Visual C++ 6.0
      Microsoft Visual C++ .NET
      g++ under Linux
*/

#include <iostream>
#include <fstream>   // needed for files
#include "employee.h"  // needed for EmployeeType


/* Given:   InFile   A binary file stream already opened for input.
   Task:    To read records of employee data from InFile and display
            them on the screen.
   Return:  InFile   The modified file stream.
*/
void DisplayFile(fstream & InFile)
   {
   int RecordSize, Count;
   EmployeeType Employee;

   Count = 0;
   RecordSize = sizeof(Employee);
   InFile.read(reinterpret_cast <char *> (&Employee), RecordSize);

   while (! InFile.fail())
      {
      PrintEmployee(Employee);
      Count++;
      if (Count == 21)
         {
         Count = 0;
         cout << endl << "Press ENTER to go on" << endl;
         cin.get();
         }
      InFile.read(reinterpret_cast <char *> (&Employee), RecordSize);
      }

   if (Count != 0)
      {
      cout << endl << "Press ENTER to go on" << endl;
      cin.get();
      }
   }


int main(void)
   {
   fstream InFile;

   InFile.open("emp.dat", ios::in | ios::binary);
   if (InFile.fail())
      {
      cerr << "Could not open file emp.dat" << endl;
      exit(1);
      }

   DisplayFile(InFile);
   InFile.close();
   return 0;
   }


