/*
  Author: Ben Carpenter (www.bencarpenter.co.uk/software)
  Date: 21st December 2004
  
  Spell checker using the dictionary web2
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(int argc, char* argv[])
{
  cout << " Spellchecker application using the dictionary 'web2'";
  fstream dict;
  string word;
  string dictionary = "web2.dic";
  bool found;
  bool done = false;
  int i=1;
  int N=0;  // Number of words in the dictionary
  
  dict.open(dictionary.data(), ios::in);
  if(!dict.is_open())
  {
    cout << endl << "\tUnable to open dictionary file" << endl;
    return 1;
  }
  else
  {
    cout << " of ";
    while(!dict.eof())
    {
      dict >> word;
      ++N;
    }
    cout << N << " words" << endl << endl;
    dict.clear();
  }
  dict.close();
  
  if(argc==1)
  {
    cout << "\tPlease enter a word to check, i.e. use 'dict hello'" << endl;
    return 1;
  }  
  
  while(!done)
  {
    dict.open(dictionary.data(), ios::in);
    found = false;
    while(!dict.eof()&&!found)
    {
      dict >> word;
      if(argv[i]==word)
      {
        cout << "\tFound: \"" << argv[i] << "\"" << endl;
        found = true;
      }
      else
      {
        if(dict.eof())
        {
          cout << "\t\"" << argv[i] << "\" not found in dictionary" << endl;
        }
      }
    }
    ++i;
    if(i==argc) done = true;
    dict.clear();
    dict.close();
  }
  return 0;
}
