I was assigned a project that requires a 2-D dynamic array of char and I am having trouble finding the proper way to define it. It is supposed to hold people's names inputted by the user. The user is supposed to be able to input as many names as they want. From what I learned in class it is supposed to look something like this.
Is this code using dynamic arrays correctly? I am very confused in the getnames function that I wrote. I know what I have is wrong, but could someone please show me an example that would use the arrays correctly? That function is supposed to read in a name from the user and store it in one row of the dynamic array. And then if the user has another input it should run again and read in the next name and store it in the next line. Any help would be appreciated, Thanks.
char ** names;
getnames(names, length, k);
cout << "Are there any more names to input?1 = yes, 2 = no " << endl;
cin >> answer;
void getnames (char ** names, int& length, int&k)
char * temp = new char [length];
cout << "Enter the competitor's name: " << endl;
length = strlen(temp);
names[k] = new char[length];