// main.cc P. Conrad, 4/5/05
// Test the Acct_C class, separate from building linked lists.
// In this program, we will just use an array of Acct_C objects.

// This program won't compile... why?

#include "acct.h"

#include <iostream>
#include <fstream>

using namespace std;

const int MAX_ACCTS = 10;

int main(int argc, char *argv[])
{

  if (argc!=2)
    {
      cerr << "Usage: " << argv[0] << " inputFile " << endl;
      return -1;
    }

  ifstream infile(argv[1],ios::in);

  if (!infile)
    {
      cerr << "Could not open " << argv[1] << endl;
      return -2;
    }

  int thisAcctNum;
  char thisName[NAME_MAX];

  Acct_C accounts[MAX_ACCTS]; // this line produces an error... why?

  int count = 0;

  infile >> thisAcctNum >> thisName;
  while (!infile.eof())
    {

      
      if (count == MAX_ACCTS)
	{
	  cerr << "Too many accounts in file... increase MAX_ACCTS and "
	       << "recompile the program." << endl;
	  return -3;
	}

      accounts[count].setName(thisName);
      accounts[count].setAcctNum(thisAcctNum);
      
      // increment count AFTER putting item in array.

      count++; // we got another item from the file successfully.

      
      // try to read the next line from the file
      infile >> thisAcctNum >> thisName;
    }
  
  cout << "The program read " << count << " lines from the file " << endl;
  cout << "Here they are: " << endl;

  for (int i=0; i<count; i++)
    cout << "\t" << accounts[i].getAcctNum //this line won't compile; why?
	 << "\t" << accounts[i].getName() << endl;

  cout << endl;
  
  return 0;

}


