Yes, character arrays can be a bit tricky, and passing and returning arrays can be tricky. There is more than one way to do what you are doing. This way does not use dynamic memory. I'm not sure if you are trying to use dynamic memory or not. Here's a way of doing it using a strict 2-D non-dynamic array.
#include <iostream>
using namespace std;
void FillArray (char nameArray[][30], int numNames)
{
for (int i = 0; i < numNames; i++)
{
cout << "Enter name " << i << " : ";
cin >> nameArray[i];
}
}
int main ()
{
char nameArray[10][30];
FillArray (nameArray, 10);
for (int i = 0; i < 10; i++)
cout << nameArray[i] << endl;
cin.get ();
cin.get ();
return 0;
}
Line 16 reserves 300 characters of space. It is assumed that the 300 characters will store 10 individual strings, each with a maximum length of 30 (including null terminator). Try entering a name that has 30 or more characters and see what happens.
The 300 characters above are guaranteed to be contiguous. Do it this way (dynamically) and that may or may not be the case.
char** nameArray;
nameArray = new char*[10];
for (int i = 0; i < 10; i++)
nameArray[i] = new char[30];
Note that, unlike in your code, I have the "new" command execute 10 times when allocating space for my characters. What are you entering inside of your getsize() function? If you want 10 strings of 30 characters each, you would need to enter ten times thirty, or 300, to reserve enough space using the code that you have. Remember, there are two sizes, not one. One size is the number of strings. The other is the number of characters in each string. It's unclear to me what you intend in the getsize () function.