Unimportant 18 Junior Poster

If you mean you want no intermediate data, you may want to sort during the merge.

Before I continue I'd like to point out that you aren't actually merging your arrays, in the code you posted. You're overwriting one.

You're also incrementing i twice. Edit: I actually have no idea what you're doing with those 2 while loops, sorry. Also please use code tags.

If you don't care about the speed of sorting, you can use this method to swap the data of two variables without creating an intermediary variable:

if( a[19] < a[18] ) {
  a[19] ^= a[18];
  a[18] ^= a[19];
  a[19] ^= a[18];
}

I don't know why you would necessarily want to do this.

You would simply need to iterate backward through your array until the if statement does not pass for a single element, you could use a size 1 smaller each time, in the worst case scenario (i<20) -> (i<19) -> (i<18)

There are better ways to sort, but that's not necessarily in the scope of this explanation.

Unimportant 18 Junior Poster

Invisi,

nArray is passed as a function parameter.

What you are doing is making another array, using memcpy to move the contents of the old array to the new one, and then deleting the old one.

You return a pointer (address of 0th element of array) to the new array from your function, this becomes nArray, which in this case is just unclear naming since you use that name in main().

You in fact, -are- deleting the array which contained your data, you obviously would not want to delete the freshly doubled in size array you made just nanoseconds before.

int* resizeArray(int* OLDArray, int oldsize, int newsize )
{
int* newArray = new int[newsize]; 
memcpy(newArray,OLDArray,oldsize*sizeof(int)); // I don't know why you bothered to omit this
delete[] OLDArray; // <--- Why not new array <--- why newArray?
OLDArray = newArray; // this way you don't have the modify the pointer later
return newArray; // <-- because newArray is what you are using in your code from now on
}
 
int main()
 
{
int sz(32);
int* nArray = new int[sz];
resizeArray( nArray, sz, (sz<<1) );
//code...

 
delete[] nArray;
nArray =0; // <-- Why are you doing this?
 
}
Unimportant 18 Junior Poster
std::stringstream ss;
ss << "A line of text."
std::ofstream file("lines.txt", std::ios::out | std::ios::app);
if(file.is_open()) file << ss.str() << '\n';
file.close();

Edit: Couple notes
You may want to read about ofstream flags, they are non-trivial.
Closing the file is important.
You don't need to use a stringstream like I did.
You should definitely check to make sure you opened the file. (shown above)

Unimportant 18 Junior Poster

You didn't post any code snippets, but it seems like you're reading or inputting uninitialized data.