You need references to arrays, since arrays cannot be passed by value (and this does not make sense, since you really want to change the original array):
template <typename T, size_t N, typename TT, size_t M> void scopy(T (&dest)[N], const TT (&src)[M]) { strncpy(dest, src, N < M ? N : M); }
You should probably also argue that sizeof(T) == 1 and sizeof(TT) == 1 , since otherwise strncpy will not do the right thing. Or, if you feel modern, replace the body:
std::copy_n(src, N < M ? N : M, dst);
source share