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

#include <Wt/WStringUtil>
#include "Dictionary.h"
#include <fstream>
#include <iostream>
#include <time.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

std::wstring RandomWord (Dictionary dictionary)


Function Documentation

std::wstring RandomWord ( Dictionary  dictionary  ) 

Definition at line 15 of file Dictionary.C.

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 }


Generated on Tue Nov 3 15:34:40 2009 for Wt by doxygen 1.5.6