File: Dictionary_8C.html

package info (click to toggle)
witty 3.2.1-2%2Bdeb7u1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 70,436 kB
  • sloc: cpp: 117,095; ansic: 77,999; xml: 7,564; sh: 1,037; perl: 208; makefile: 144; java: 86; sql: 14
file content (134 lines) | stat: -rw-r--r-- 5,941 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Wt examples: /home/koen/project/wt/public-git/wt/examples/hangman/Dictionary.C File Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Wt examples
   &#160;<span id="projectnumber">3.2.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">/home/koen/project/wt/public-git/wt/examples/hangman/Dictionary.C File Reference</div>  </div>
</div>
<div class="contents">
<div class="textblock"><code>#include &lt;Wt/WApplication&gt;</code><br/>
<code>#include &lt;Wt/WStringUtil&gt;</code><br/>
<code>#include &quot;<a class="el" href="Dictionary_8h_source.html">Dictionary.h</a>&quot;</code><br/>
<code>#include &lt;fstream&gt;</code><br/>
<code>#include &lt;iostream&gt;</code><br/>
<code>#include &lt;time.h&gt;</code><br/>
<code>#include &lt;stdlib.h&gt;</code><br/>
</div>
<p><a href="Dictionary_8C_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">std::wstring&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="Dictionary_8C.html#addb438135bbc4b68a5ff5b6c6dfa5dd4">RandomWord</a> (<a class="el" href="Dictionary_8h.html#a75d0a1670704923e348986686c3714f9">Dictionary</a> dictionary)</td></tr>
</table>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="addb438135bbc4b68a5ff5b6c6dfa5dd4"></a><!-- doxytag: member="Dictionary.C::RandomWord" ref="addb438135bbc4b68a5ff5b6c6dfa5dd4" args="(Dictionary dictionary)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::wstring RandomWord </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="Dictionary_8h.html#a75d0a1670704923e348986686c3714f9">Dictionary</a>&#160;</td>
          <td class="paramname"><em>dictionary</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Definition at line <a class="el" href="Dictionary_8C_source.html#l00016">16</a> of file <a class="el" href="Dictionary_8C_source.html">Dictionary.C</a>.</p>
<div class="fragment"><pre class="fragment">{
   std::ifstream dict;
   <span class="keywordflow">if</span> (dictionary == <a class="code" href="Dictionary_8h.html#a75d0a1670704923e348986686c3714f9a7b7a0d1c13d5ae5a4e27e17b7b6e26c1">DICT_NL</a>) {
     dict.open((<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a88b082dadadd3fb7dbe10887e7d89c91">Wt::WApplication::appRoot</a>() + <span class="stringliteral">&quot;dict-nl.txt&quot;</span>).c_str());
   } <span class="keywordflow">else</span> { <span class="comment">// english is default</span>
     dict.open((<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a88b082dadadd3fb7dbe10887e7d89c91">Wt::WApplication::appRoot</a>() + <span class="stringliteral">&quot;dict.txt&quot;</span>).c_str());
   }
      
   std::string retval;
   <span class="keywordtype">int</span> numwords = 0;
   <span class="keywordflow">while</span>(dict) {
      getline(dict, retval);
      numwords++;
   }
   dict.clear();
   dict.seekg(0);

   srand(time(0));
   <span class="keywordtype">int</span> selection = rand() % numwords; <span class="comment">// not entirely uniform, but who cares?</span>

   <span class="keywordflow">while</span>(selection--) {
      getline(dict, retval);
   }
   getline(dict, retval);
   <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; retval.size(); ++i)
      <span class="keywordflow">if</span>(retval[i] &lt; <span class="charliteral">&#39;A&#39;</span> || retval[i] &gt; <span class="charliteral">&#39;Z&#39;</span>)
         std::cout &lt;&lt; <span class="stringliteral">&quot;word &quot;</span> &lt;&lt; retval 
                   &lt;&lt; <span class="stringliteral">&quot; contains illegal data at pos &quot;</span> &lt;&lt; i &lt;&lt; std::endl;

   <span class="keywordflow">return</span> Wt::widen(retval);
}
</pre></div>
</div>
</div>
</div>
<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Fri Mar 30 2012 for <a href="http://www.webtoolkit.eu/wt">the
C++ Web Toolkit (Wt)</a> by&nbsp;<a
href="http://www.doxygen.org/index.html"><img src="doxygen.png"
alt="doxygen" border="0" style="vertical-align: middle; display:
inline-block; height: 2em"></a> 1.7.5.1</small></address>
</body>
</html>