I have two text files, firstnames.txt and lastnames.txt. There are 20 names in each, and they are all on a new line. I need to make a random name generator in my program.
I'm not allowed to use string[] so I have to use char*[]. So far, my plan is to add all of the names into the char*[] array, and then make a random number between 1 and 20 and get that index to get a random name. I'm stuck on how to get the names from the text file into a char*[].
Here's what I have so far:
int a = 0;
//Open first name file
ifstream fnameFile;
fnameFile.open("firstnames.txt");
char* fname[20];
//Put names from file into char*[] array
while (fnameFile.good()) {
getline(fnameFile, fname[a]);
a++;
}
The getline() doesn't work with the char*[] array though, so how do I get these names into the array?