Function to copy one array to another with bounds checking. It does work with all types. Copy this code into a header file called ArrayCopy.h. In main file code do this.
...
int destinationArray[some size1];
int sourceArray[some size2]= {1,2,3,4,5,6};
CopyArray(destinationArray, source array, some size1, some size2);
...
#ifndef ARRAYCOPY_H
#define ARRAYCOPY_H
#include <iostream>
template <typename type>
void CopyArray( type *tA, type *tB, int aSize, int bSize) // destination, source, size of destination, size of source
{
if(aSize == bSize)
{
for (int iii = 0; iii < bSize; ++iii)
{
tA[iii]= tB[iii];
}
}
else if(aSize > bSize)
{
int difference = aSize-bSize;
int position = aSize-difference;
for (int iii = 0; iii < bSize; ++iii)
{
tA[iii]= tB[iii];
}
for (position; position < aSize; ++position)
{
tA[position] = 0;
}
}
else if(bSize > aSize)
{
for (int iii = 0; iii < aSize; ++iii)
{
tA[iii]= tB[iii];
}
}
else
{
cerr << "Oops, Something Has Gone Awry. Cannot Copy.";
}
}
#endif