如何从给定的偏移量开始复制内存。例如
int main()
{
int a1[100], a2[100], i;
errno_t err;
// Populate a2 with squares of integers
for (i = 0; i < 100; i++)
{
a2[i] = i*i;
}
// Tell memcpy_s to copy 10 ints (40 bytes), giving
// the size of the a1 array (also 40 bytes).
err = memcpy_s(a1, sizeof(a1), a2, 10 * sizeof (int) );
if (err)
{
printf("Error executing memcpy_s.\n");
}
else
{
for (i = 0; i < 10; i++)
printf("%d ", a1[i]);
}
printf("\n");
}如何将内存从a2复制到a1,从a1的索引50开始。
提前感谢
发布于 2012-08-17 05:51:20
在a1上加上50。不需要对sizeof进行加法运算;编译器知道如何做。
发布于 2012-08-17 05:51:20
将地址传递到要复制到的索引,作为memcpy的目标
memcpy(&a1[50], &a2[50], 10 * sizeof a[0]);https://stackoverflow.com/questions/11995938
复制相似问题