How can I write any letter and let c++ to display random words for me ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I write any letter and let c++ to display random words for me ?

Letter random word

5th Dec 2019, 11:21 AM
The unknown 321
The unknown 321 - avatar
3 Answers
+ 2
You could use a char array. But I highly discourage you from doing so. Because you'll have to work with char** type and no one likes double pointers. I recommend a vector of strings instead. https://en.cppreference.com/w/cpp/container/vector https://en.cppreference.com/w/cpp/string/basic_string Simply do something like std::vector<std::string> words = { "word1", "word2", "word3", etc }; I'll let you do the rest, if you need more help, feel free to ask. I do expect to see code before I can help with more specific problems though.
5th Dec 2019, 6:52 PM
Dennis
Dennis - avatar
+ 1
First you'll need random words to begin with. With a little bit of googling you can find a large txt file with thousands of dictionary words. Then, simply load the entire file into a data structure. I recommend the Trie data structure as it is designed for fast lookup of strings given the first few characters. https://en.m.wikipedia.org/wiki/Trie Or, you could just hardcode a small array with strings.
5th Dec 2019, 3:21 PM
Dennis
Dennis - avatar
+ 1
Thanks. But can I do this using "Char" array ? If yes please show me a code example
5th Dec 2019, 5:26 PM
The unknown 321
The unknown 321 - avatar