/* This program uses class Strings to scan a file for a given string,
   simulating the behavior of a virus detection program.

   Input:  The name of the input file; the string to be checked
   Output: A message indicating whether the input string occurs
           in the input file
---------------------------------------------------------------------*/

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include "Strings.h"

int main(void)
{
   cout << "\nThis program searches a file for a given string.";

   Strings
      FileName,                           // the input file name
      SearchString,                       // the string being sought
      InputString;                        // a line from input file

																					// get name of input file
   cout << "\nPlease enter the name of the file to be searched: ";
   FileName.GetLine(cin);

   fstream
      InStream(FileName, ios::in);        // open a stream to it

   if (InStream.fail())                   // check for successful open
   {
      cerr << "\n*** main: unable to open " << FileName
           << " for input!\n";
      exit(-1);
   }
                                          // get the search string
   cout << "\nPlease enter the string being sought: ";
   SearchString.GetLine(cin);

   InputString.GetLine(InStream);         // get the first line
   while (!InStream.eof())                // while not end-of-file
   {                                      // if line contains string
                                          //   display a "found" msg.
      if (InputString.Position(SearchString) >= 0)
          cout << "\n***" << SearchString
               << " found in this file.\n";

      InputString.GetLine(InStream);      // get the next line
   }

   cout << "\nProcessing complete.\n\n";  // message to user
   InStream.close();                      // close the file
   return 0;
}
