/home/koen/project/wt/cvs/wt/examples/hangman/Dictionary.C

Go to the documentation of this file.
00001 /* this is a -*-C++-*- file
00002  * Copyright (C) 2005 Wim Dumon
00003  *
00004  * See the LICENSE file for terms of use.
00005  */
00006 
00007 #include <Wt/WStringUtil>
00008 
00009 #include "Dictionary.h"
00010 #include <fstream>
00011 #include <iostream>
00012 #include <time.h>
00013 #include <stdlib.h>
00014 
00015 std::wstring RandomWord(Dictionary dictionary)
00016 {
00017    std::ifstream dict;
00018    if(dictionary == DICT_NL) {
00019       dict.open("dict-nl.txt");
00020    } else { // english is default
00021       dict.open("dict.txt");
00022    }
00023       
00024    std::string retval;
00025    int numwords = 0;
00026    while(dict) {
00027       getline(dict, retval);
00028       numwords++;
00029    }
00030    dict.clear();
00031    dict.seekg(0);
00032 
00033    srand(time(0));
00034    int selection = rand() % numwords; // not entirely uniform, but who cares?
00035 
00036    while(selection--) {
00037       getline(dict, retval);
00038    }
00039    getline(dict, retval);
00040    for(unsigned int i = 0; i < retval.size(); ++i)
00041       if(retval[i] < 'A' || retval[i] > 'Z')
00042          std::cout << "word " << retval << " contains illegal data at pos " << i << std::endl;
00043 
00044    return Wt::widen(retval);
00045 }
00046 

Generated on Fri Jul 25 17:05:59 2008 for Wt by doxygen 1.5.3