I’m programming hangman.
Question words are saved in char word_list[], const strings.
word_list[] = {"apple", "computer", ..., "mouse"};
Question is randomly selected from word_list[], and when I use random function I want to know the number of strings in word_list[].
word_list is the pointer of char*, right?
Finally, how can I know the number of strings in word_list[]??
If
word_list[]is declared like your code snippet you can obtain the number of elements by doing:You might consider a more flexible method like reading a
std::vectorofstd::stringat run time. That would allow you to modify the word list without having to recompile and thevector::size()function would tell you the number of elements.