Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用memcpy将二维数组复制到新缓冲区_C_Arrays_Multidimensional Array_Nested Loops - Fatal编程技术网

使用memcpy将二维数组复制到新缓冲区

使用memcpy将二维数组复制到新缓冲区,c,arrays,multidimensional-array,nested-loops,C,Arrays,Multidimensional Array,Nested Loops,我想将二维数组复制到内部缓冲区内的新二维数组 假设我有以下函数: uint8 the_2D_array[100][7]; void Get_2D_Array(uint8 **array) { *array = &the_2D_array[0][0]; // Function which returns pointer to the first element of the 2D array } 稍后在我的代码中,我将执行以下操作: myBuffered_Aray[100][

我想将二维数组复制到内部缓冲区内的新二维数组

假设我有以下函数:

uint8 the_2D_array[100][7];

void Get_2D_Array(uint8 **array)
{
   *array = &the_2D_array[0][0];   // Function which returns pointer to the first element of the 2D array
}
稍后在我的代码中,我将执行以下操作:

myBuffered_Aray[100][7];
uint8 *pValues;

Get_2D_Array(&pValues)
{
  for (uint8 i = 0; i < 100; i++)
  { 
     for (uint8 j = 0; j < 7; j++)
     {
        (void)memcpy(myBuffered_Aray[i][j], (u8_t*)&pValues[i][j], sizeof(uint8));
     }   
  }
由于“表达式必须具有指向对象类型的指针”,因此无法工作


如何正确操作?

uint8**array
(双指针)与数组没有任何关系。要将
uint8(*array)[7]
作为参数(指向
uint8[7]
数组的指针),请参阅:以获取进一步的说明。您不需要在循环中包含
memcpy
来复制2D数组,它只是
memcpy(myBuffered_数组,array,100*7*sizeof(uint8))
——无循环。(在嵌套循环中使用
memcpy
一次复制一个
uint8
是没有意义的——您可以简单地使用赋值)。如果您提供,我或其他人可以帮助您进一步了解具体情况。错误更可能指向第一个参数
myBuffered_Aray[i][j]
。应该是
&myBuffered\u Aray[i][j]
。到底什么是
u8\u t
?复制粘贴实际代码。最后,为什么要执行700个memcpy调用而不是1个?那效率很低。
(u8_t*)&pValues[i][j]