// staticArray.cc   Demo of reading into static array from file
// P. Conrad for CISC181, 06S

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
  if (argc!=2)
    {
      cerr << "Usage: " << argv[0] << " filename" << endl;
      exit(1);
    }


  // try to open the input file
  
  ifstream infile(argv[1],ios::in);

  // if file could not be opened, print error message and exit

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

  // read the data into the array

  int x;
  int count=0;

  const int MAX_SIZE = 500;
  int nums[MAX_SIZE];

  infile >> x;
  while (!infile.eof())
    {
      // store data in array
      nums[count] = x;
      count ++;

      infile >> x;
    }

  // use array
  
  for (int i=0; i<count; i++)
    {
      cout << "nums[" << i << "]=" << nums[i] << endl;
    }

  return 0;
}
