I'm trying read an array of a size unbeknownst to me.To start reading in the values of the array, I start out with a size of 10, and when I reach capacity I call a function to resize the array. Here's where I'm having trouble when I call the function, it resizes the array once and stops reading in the rest of the values. On top of that, when I try to add the values the program did managed to read in, I get a negative number. If anyone could point me in the right direction, I would be very thankful.
In resize you pass a pointer by value. You then change the value of that pointer. But, since the pointer was passed by value nothing outside of the function is affected. In main you still have a pointer to the memory that was deallocated in the function. Of course, if that wasn't the case you would still have an in valid pointer in main since you delete your newly allocated array before you leave resize.
Line 40: arr is a pointer that is passed by value. Setting it to newArr serves no purpose. Both arr and newArr go out of scope when resize() exits.
Line 41: Why are you deleting newArr after you just got through building it?
Line 42: You need some way of returning newArr back to main. The usual way to do this is to make resize return an int pointer (to newArr). Line 23 of course has to be changed to set arr to the return value from resize.