/**********************************************************************

File: searchkeys.cc
Nov. 30 1999
K.Becker

Purpose: check for found/not found keys in a table

**********************************************************************/


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

const int TABLE_MAX = 800;

		
/********************** BEGIN MAIN **********************************/
int main ()
{
  char inname[128];              // input file name
  fstream infile;               // the input file

  char keyname[128];             // key file name
  fstream keyfile;              // the file

  int table[TABLE_MAX];  // the dictionary table
  int i,j,k;                    // for whatever
  char mess[4096];              // the message

  int N;
  int slen;
  int found;

  int key;
  int nfound = 0;
  int nnot = 0;

  cout << "Entername of file containing original keys please: ";
  cin >> keyname;
  keyfile.open(keyname, ios::in);

  if (keyfile.rdstate() != 0)  // problem opening file?
    {
      cout << "Unable to open file: " << keyname << endl;
      cout << "Code is: " << keyfile.rdstate() << endl;
      exit(1);
    }


  cout << "Entername of file containing keys to search for please: ";
  cin >> inname;
  infile.open(inname, ios::in);

  if (infile.rdstate() != 0)  // problem opening file?
    {
      cout << "Unable to open file: " << inname << endl;
      cout << "Code is: " << infile.rdstate() << endl;
      exit(1);
    }

  for (i = 0; i < TABLE_MAX; i++)
    keyfile >> table[i];

  while (!infile.eof())
    {
      found = 0;
      infile >> key;
      for (i = 0; i < TABLE_MAX; i++)
	if (table[i] == key)
	  found = 1;
      if (found)
	nfound++;
      else
	nnot++;
    }

  cout << "Found: " << nfound << endl;
  cout << "NOT: " << nnot << endl;
cout << "DONE." << endl;

} // END PROGRAM ---
