I have to write a code for class where the user inputs how many colors he wants to enter and then after that the user enters the different colors. I have to use an array of course to store all these colors in, but I just want to make sure that I'm using everything correctly before I continue on. It compiles and runs just fine, but I still feel like I'm using dynamic memory wrong here.
delete[] ColorArray deletes ALL memory taken in the array.
You would want to do something like ColorArray = new string [Amount];
After the player enters in the Amount. Then delete it when you never need to use the data again.
Okay, I have one more question actually. I have to write a function that takes string pointers and length parameters as parameters. I've been searching all day about this as well and don't really get what my teacher want's by that. How do I add a string pointer? would it just be this
I'm getting this error now, and I cant figure out for the life of me what to do next.
a09.cpp: In function ‘int main()’:
a09.cpp:41:21: error: expected primary-expression before ‘*’ token
print_array(string *ColorArray, int Amount);
^
a09.cpp:41:34: error: expected primary-expression before ‘int’
print_array(string *ColorArray, int Amount);