simple memcpy() question
-
I have a number a different arrays.
double t1[10];
char t2[10];
...double cpT1[10];
char cpT2[10];If I make a array of the same size to copy into can I use the memcpy() function like this?
memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.
memcpy(cpT2, t2, sizeof(t2));
Or should I create a function that I pass the amount to the memcpy() function? If So how can I make it so that I can pass any array to the function? Thanks, steven
-
I have a number a different arrays.
double t1[10];
char t2[10];
...double cpT1[10];
char cpT2[10];If I make a array of the same size to copy into can I use the memcpy() function like this?
memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.
memcpy(cpT2, t2, sizeof(t2));
Or should I create a function that I pass the amount to the memcpy() function? If So how can I make it so that I can pass any array to the function? Thanks, steven
If the array are statically created (like in your example), that will work, otherwise not !
-
I have a number a different arrays.
double t1[10];
char t2[10];
...double cpT1[10];
char cpT2[10];If I make a array of the same size to copy into can I use the memcpy() function like this?
memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.
memcpy(cpT2, t2, sizeof(t2));
Or should I create a function that I pass the amount to the memcpy() function? If So how can I make it so that I can pass any array to the function? Thanks, steven
memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.
memcpy(cpT2, t2, sizeof(t2));This will work fine. John
-
If the array are statically created (like in your example), that will work, otherwise not !
thanks, sj
-
memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.
memcpy(cpT2, t2, sizeof(t2));This will work fine. John
thanks, sj