Hope something in here meets your needs and helps you understand the syntax.
char * wordArr[10];
means wordArr is an array of 10 char pointers, not that wordArray is a pointer to 10 char arrays.
char * word = new char[10];
means word is a pointer to a char array that can contain up to 10 char.
Now, an example of putting words into array directly. without need for user termination
#include <iostream>
using namespace std;
int main()
{
char word[10]= "";
char wordArr[10][10];
int i;
for(i = 0; i < 10; ++i)
cin >> wordArr[i];
for(i = 0; i < 10; ++i)
cout << wordArr[i] << endl;
cin.get();
}
Inputting words into an array indirectly
#include <iostream>
using namespace std;
int main()
{
char word[10] = "";
char wordArr[10][10];
int i;
for(i = 0; i < 10; ++i)
{
cin >> word;
strcpy(wordArr[i], word);
}
for(i = 0; i < 10; ++i)
cout << wordArr[i] << endl;
cin.get();
}
Using pointer to pointer to char instead of array of char arrays
#include <iostream>
using namespace std;
int main()
{
char **wordArr;
int i, j, k;
cin >> i;
cin >> j;
wordArr = new char*[i];
for( j = 0; j < i; ++i)
wordArr[i] = new char[j];
for(j = 0; j < i; ++j)
cin >> wordArr[j];
for(j = 0; j < i; ++j)
cout >> wordArr[j] << endl;
for(j = 0; j < i; ++j)
delete[] wordArr[i];
delete wordArr;
cin.get();
}
Using array of char pointers instead of pointer to pointer to char
#include<iostream>
using namespace std;
int main()
{
char *wordArr[10];
int i, j;
cin >> j;
for(i = 0; i < 10; ++i)
wordArr[i] = new char[j];
for(i = 0; i < 10; ++i)
cin >> wordArr[i];
for (i = 0; i < 10; ++i)
cout << wordArr[i] << endl;
for(i = 0; i < 10; ++i)
delete[] wordArr[i];
cin.get()
}
Another version using array of char pointers:
#include <iostream>
using namespace std;
int main()
{
char * wordArr[2] = { {"Hello"}, {"World"} };
cout << wordArr[0] << ' ' << wordArr[1] << endl;
cin.get()
}