32 template <
class T>
int Tmycpy( T a, T b,
size_t size,
int numElements)
39 std::cout <<
"INITIAL ARRAY CONTENTS: " <<
"a=" ;
40 for(
int i=0; i < numElements; i++)
45 for(
int i=0; i < numElements; i++)
51 <<
"numElements=" << numElements
70 if(memcmp(static_cast<void *>(a), static_cast<void *>(b), size) != 0)
77 int main(
int argc,
char *argv[])
81 char ca1[] = {
"123456789"};
82 char ca2[
sizeof(ca1)];
85 memset(ca2,
'x',
sizeof(ca2));
90 int i = Tmycpy<char *>(ca1, ca2,
sizeof(ca2),
sizeof(ca2)/
sizeof(char));
94 std::cout <<
"SUCCESS: " 99 <<
"elements copied=" << i
102 std::cout <<
"#############################" << std::endl;
105 int ia[] = {9,8,7,6,5,4,3,2,1,0};
106 int ib[] = {0,0,0,0,0,0,0,0,0,4};
112 i = Tmycpy<int *>(ia, ib,
sizeof(ib),
sizeof(ib)/
sizeof(*ib));
117 std::cout <<
"SUCCESS: int array works too" 119 <<
"elements copied=" << i
122 std::cout <<
"SECOND ARRAY CONTENTS: " <<
"ia=" ;
123 for(
int j=0; j < i; j++)
128 for(
int j=0; j < i; j++)
131 std::cout << std::endl;
133 std::cout <<
"#############################" << std::endl;
int Tmycpy(T a, T b, size_t size, int numElements)
Template function to copy a string literal.
int main(int argc, char *argv[])