//
// Program:  countlines
//
// Purpose:  count lines in input file.
//
// Input:
//   File name, from standard input.
// Output:
//   Number of lines in specified file, to standard output.
//

#include <iostream.h>
#include <fstream.h>		// has ifstream
#include <stdlib.h>		// has exit(), EXIT_*
#include <iomanip.h>		// has setw()

int main()
{
  ifstream infile;
  const int BUFFSIZE=1000;
  char filename[BUFFSIZE];
  
  // Obtain name of input file.
  cout << "Name of input file?  ";
  cin >> setw(BUFFSIZE) >> filename;

  // Open file.
  infile.open(filename);
  if (!infile)
    {
      cout << "Unable to open " << filename << endl;
      exit(EXIT_FAILURE);
    }

  // Count lines.
  int count = 0;
  char line[BUFFSIZE];
  while (infile.getline(line, BUFFSIZE)) // reads one line into "line"
    ++count;

  // Close file and print result.
  infile.close();
  cout << count << " lines\n";
  return EXIT_SUCCESS;
}