Enumerations | Functions

/home/koen/project/wt/public-git/wt/examples/hangman/Dictionary.h File Reference

#include <string>

Go to the source code of this file.

Enumerations

enum  Dictionary { DICT_EN = 0, DICT_NL = 1 }

Functions

std::wstring RandomWord (Dictionary dictionary)

Enumeration Type Documentation

enum Dictionary
Enumerator:
DICT_EN 
DICT_NL 

Definition at line 12 of file Dictionary.h.

                {
  DICT_EN = 0,
  DICT_NL = 1
};

Function Documentation

std::wstring RandomWord ( Dictionary  dictionary )

Definition at line 16 of file Dictionary.C.

{
   std::ifstream dict;
   if (dictionary == DICT_NL) {
     dict.open((Wt::WApplication::appRoot() + "dict-nl.txt").c_str());
   } else { // english is default
     dict.open((Wt::WApplication::appRoot() + "dict.txt").c_str());
   }
      
   std::string retval;
   int numwords = 0;
   while(dict) {
      getline(dict, retval);
      numwords++;
   }
   dict.clear();
   dict.seekg(0);

   srand(time(0));
   int selection = rand() % numwords; // not entirely uniform, but who cares?

   while(selection--) {
      getline(dict, retval);
   }
   getline(dict, retval);
   for(unsigned int i = 0; i < retval.size(); ++i)
      if(retval[i] < 'A' || retval[i] > 'Z')
         std::cout << "word " << retval << " contains illegal data at pos " << i << std::endl;

   return Wt::widen(retval);
}

Generated on Fri Jul 8 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.2