Enumerations | Functions

/build/buildd/witty-3.1.2/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 15 of file Dictionary.C.

{
   std::ifstream dict;
   if(dictionary == DICT_NL) {
      dict.open("dict-nl.txt");
   } else { // english is default
      dict.open("dict.txt");
   }
      
   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 Sat Dec 4 2010 06:32:31 for Wt by doxygen 1.7.2