You are getting a compile error because you trying to assign a char* to an array of chars.
Since wordbank is a 2D array wordbank[index] will be a char* (pointer to char). C and C++ has no implicit conversion from char* to array of char. Consequently you'll get a compile error.
If you want a copy of a random string in wordbank, it can be done like this:
char wordbank[5][20] = {"house", "car", "tree", "bicycle", "shark"};
srand (time(NULL));
int random = rand() % 5;
char word[20];
strcpy(word, wordbank[random]); // strcpy (string copy) takes a copy of the 2nd string
// (i.e. wordbank[random]) and puts it into the 1st
// string (i.e. word).
If you just want to point to a random string in wordbank, it ca be done like this:
char wordbank[5][20] = {"house", "car", "tree", "bicycle", "shark"};
srand (time(NULL));
int random = rand() % 5;
char* word = wordbank[random]; // word is a pointer to a string. It is
// initialized to point to the string
// held by wordbank[random]
With the first method you can change the value of word without changing the value of wordbank. With the second method you will change both at the same time.
BTW - use std::string instead of C-style string and vector instead of array. If you really want an array the use the C++ style instead.
Something like:
vector<string> wordbank; // Make a vector of strings to hold your wordbank
wordbank.push_back("house"); // Add words to wordbank one-by-one
wordbank.push_back("car"); // ...
wordbank.push_back("tree"); // ...
wordbank.push_back("bicycle"); // ...
wordbank.push_back("shark"); // ...
// or add all words at initialization - like:
//vector<string> wordbank {"house", "car", "tree", "bicycle", "shark"};
srand (time(NULL));
int random = rand() % wordbank.size();
string word = wordbank[random]; // Copy wordbank[random] into word
Now you can just add new words to wordbank without carrying about how many words it contains and how long the individual words are.
std::stringin C++. Also, make sure to specify exact error messages. We can't see your computer screen.wordbankandwordbook- I assume they should be the same...