I tried to create an array that would increase its own size depending on the user's action.
For example:
The user types the name of one contestant, the array contains only one element (the name), later the user enters another contestant, the array becomes an array of 2 elements, each element with the corresponding name, etc...
The problem is that for some mysterious reason the program crashes at contestant number 10, I have tried to use delete [] name_address, every time the loop iterate, but it just made the program crash at contestant number 6.
If anyone has an explanation, please do so.
Code:
int array_subscript;
double averages_final[3];
double score[5];
char input[40];
int number_of_contestants = 0;
string name;
string *name_address;
while (true)
{
cout << "Contestant " << number_of_contestants + 1 << " name? (Enter '!' when finished) ";
getline(cin, name);
if (name == "!")
break;
number_of_contestants++;
name_address = new string[number_of_contestants];
static string *pointer = 0;
for (int i = 0 ; i < number_of_contestants - 1 ; i++)
name_address[i] = pointer[i];
name_address[number_of_contestants-1] = name;
string names[number_of_contestants];
for (int i = 0 ; i < number_of_contestants ; i++)
names[i] = name_address[i];
pointer = names;
}