So I am writing quite a long code and now I came to a problem. How to change structure's arrray's values and get them back to main function. What I am trying to do this function is: to insert a new value at first array spot(which is 0). The whole for cycle frees the Z[0] and works fine. But I do not know how to return whole CHANGED structure array to the main program. How to do this?
Thank you. P.S. sorry, for my broken english.
Here are the neccessary parts of the code:
void insertion(Player Z[], int size); //declaration of the funcion
...
int main()
{
int size=5;
Player *Z = new Player[size];
Insertion(Z, size); //calling the function
...
}
void Insertion(Player Z[], int size) //function
{
size++;
Player* temp = new Player[size];
for(int i=0;i<=size-1;i++)
{
temp[i+1]=Z[i];
}
delete [] Z;
Z = temp;
cin>>Z[0].name;
cin>>Z[0].surname;
}
std::vector<Player>.std::vector. If yours does not, then throw it away.std::vectoris one of the C++ standard container classes. It's part of the language. You use it by default for every problem of the "I have a collection of X things, and X will only be known when the program runs" kind. Do not usenew[].