// readNames3.cc read first and last names from a file
// using getline
// P. Conrad for CISC181 06S   02/17/06

#include <iostream>
#include <fstream>

#include <cstring> // equivalent to doing #include <string.h> in C

using namespace std;

// following line of code changes every instance of NAMELEN
// to be 32

// the terminology for such a line is
//    #define constant
//    more generally, anything that starts with # is a pre-processor directive

// 

#define NAMELEN 32

#define INPUT_FILENAME "fullNames.dat"

int main(void)
{
  
  ifstream infile(INPUT_FILENAME, ios::in);

  if (!infile)
    {
      cerr << "Could not open "<< INPUT_FILENAME << endl; // !??!?
      exit(1);
    }

  char name[NAMELEN];


  // unlike infile >> name, which will use whitespace to separate
  // one string from the next, infile.getline() will read an entire
  // line from our file

  infile.getline(name,NAMELEN);  // we changed this line
  
  while (!infile.eof())
    {
      // process the input line

      int length = strlen(name);

      cout << "The length of " << name << " is " << length << endl;


      // try to read the next line
      
      infile.getline(name, NAMELEN);  // and this one
    }

  infile.close(); // close the file when we are done with it

  return 0; // successful completion.

}

