I have to write a program that creates a dynamic array of five strings, store them and be able to access them.
This is the code I have written so far. The console receives the information that is inputted, but I believe does not store them. Also I commented out the cout on line 33 that was suppose to test the entry. Mainly because it makes the program go into an infinite loop. I've got a big suspicion that the whole thing is wrong, but I am not a hundred percent sure. Any help you can offer would be greatly appreciated.
#include<iostream>
#include <string>
using namespace std;
typedef char* CharArray;
const int NAMES = 5;
void getNames(string Name, CharArray nameArray);//getNames function declaration
int main()
{
CharArray nameArray;
nameArray = new char[NAMES];
string Name;//Variable name for this string
getNames(Name, nameArray);//Function call for getNames
return 0;
}
void getNames(string Name, CharArray nameArray)//Function definition
{
for ( int i = 0; i < NAMES; i++ )//Used to iterate the strings that are being created.
{
cout << "\nPlease enter name " << i + 1 << ".";//Output o instrct user to enter names.
cin >> Name;//Recieves info from user
}
// cout << Name:
}