Hello, how do I use variables "Number" and "Price" in another function after setting them from normal variable to array with "new" ? And why cant I display new array outside "ReadFile" function ? P.S Sorry about using quotes instead of format, but it doesnt seem to work.
You need to pass a pointer to the function ReadFile.
1 2 3 4 5 6 7 8
int main()
{
int DifferentBooks, *Number;
double *Price;
ReadFile(DifferentBooks, Number, Price);
return 0;
}
You can pass Number and Price to other functions as well.
Don't forget to delete your arrays when you are finished.
If arrays are not required by an assignment then consider using vectors or lists instead.
I feel so stupid now, I accidently renamed my text file :| Everything seems to be working now, and as I understood, I need to use "delete" only at the end of the program ?
I need to use "delete" only at the end of the program ?
In this case yes. But there may be other circumstances where you want to allocate some memory just for the duration of a certain part of the process, in that case use delete [] when you no longer need the allocated memory.
Though if possible, the use of raw pointers should be avoided. C++ has smart pointers which take care of their own resources. Or in this case as Thomas1965 suggested, you might better use a vector or a list instead.