When you say:
char word[80] = {0};
You are telling the compiler to allocate 80 characters in an array for you to use.
When you say:
char *words[80] = {0};
You are telling the compiler to allocate 80 pointers to a char type. So in essence you have allocated space for 80 potential words, but there pointers are not pointing anywhere at the moment.
Your array 'words' looks like this:
Code:
words[0] = NULL;
words[1] = NULL;
words[2] = NULL;
...
words[79] = NULL;
To use it you need to allocate space and assign data to it.
For example:
Code:
words[0] = strdup("This");
words[1] = strdup("is");
words[2] = strdup("a");
words[3] = strdup("sentence.");
...
This is an array of pointers to char* which is what char *[80] allocated for you.
When you are done, each of the lements that you allocated MUST be free'd or you will leak memory:
Code:
free(words[0]);
free(words[1]);
free(words[2]);
free(words[3]);
Usually this can be done in a following way:
Code:
for (int i=0; i<80; ++i) {
if (words[i]) {
delete words[i];
words[i] = NULL;
}
}
Since we are in the C++ world you should be using something akin to:
Code:
std::string words[80];
words[0] = "This";
words[1] = "is";
words[2] = "a";
words[3] = "sentence";
and not worry about deallocation, as the std::string class will delete the data in its destructor when the obect is removed from scope.