//==============================================================================
//
//  File name ......: ReadingFromInputFile.cc
//  Author(s) ......: Leen-Kiat Soh
//  Language .......: C++
//  Started ........: February 1 2004
//  Last modified ..: February 3 2004
//  Version ........: 1.0
//  Source Path ....: .
//  Site ...........: Department of Computer Science and Engineering
//                    University of Nebraska
//                    Lincoln, NE 68588-0115
//                    U.S.A.
//  Purpose ........: This reads in several lines of tokens until it reads
//		      "END".  This is not a complete program.  It simply shows
//		      how to read from an input file and how to extract the
//		      tokens from each line.
//  Note ...........: Adapted from a program originally written by Binita
//                    Baniya
//==============================================================================

#include <stdlib.h>
#include <fstream>
#include <iostream.h>
#include <string>

using namespace std;

/**
 * This function obtains the "substring" of a string given the starting point
 * and the next space.
 */

string getSub(int &start, const string in)  {	

   int end;
   end = in.find(" ", start);

   string tmpStr = in.substr(start, end-start);
   start = end+1;

   return tmpStr;

}  // end getSub

/**
 * This is the main function to read in an input file and parse the lines from
 * the input file.
 */

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

   ifstream fileIn;
   string inLine;
   string data;

   // Open the input file
   fileIn.open(argv[1]);   // open the input file from the command line

   getline(fileIn,inLine);  // read the first line from the input file

   while (!inLine.empty() && inLine.c_str() != "END")  {

       data = getSub(start,inLine);  // get the first token
       while (start != 0) {
          data = getSub(start,inLine);
          start += data.length();
          }

       getline(fileIn,inLine);   // read the next line
      
   }  // end while

   return 0

}

