Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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_Pointers_Memcpy - Fatal编程技术网

通过memcpy复制阵列

通过memcpy复制阵列,c,arrays,pointers,memcpy,C,Arrays,Pointers,Memcpy,我看到有很多关于memcpy的文章,但我找不到解决问题的方法。有人能理解为什么复制操作不起作用吗 float MeanFilter(const volatile float *Array, volatile float Dist){ float Avg = 0.0; // Variable used to calculate the average distance value float Sorted[MaxDistArray]; // Array used to contain the

我看到有很多关于memcpy的文章,但我找不到解决问题的方法。有人能理解为什么复制操作不起作用吗

float MeanFilter(const volatile float *Array, volatile float Dist){
float Avg = 0.0;    // Variable used to calculate the average distance value
float Sorted[MaxDistArray]; // Array used to contain the sorted array

printf("\n");
int j;

for(j = 0; j < 20; j++){
    if(j == 10) printf("\n \t");
    printf("%d: %f, ", j+1, Array[j]);
}

memcpy(Sorted, &Array[0], sizeof(float));
Sort(Sorted);   // Sort the array of distances values

printf("\n");

for(j = 0; j < 20; j++){
    if(j == 10) printf("\n \t");
    printf("%d: %f, ", j+1, Sorted[j]);
}
float-MeanFilter(常量volatile-float*数组,volatile-float-Dist){
float Avg=0.0;//用于计算平均距离值的变量
浮点排序[MaxDistArray];//用于包含排序数组的数组
printf(“\n”);
int j;
对于(j=0;j<20;j++){
如果(j==10)printf(“\n\t”);
printf(“%d:%f,”,j+1,数组[j]);
}
memcpy(排序,&数组[0],sizeof(float));
排序(已排序);//对距离值数组进行排序
printf(“\n”);
对于(j=0;j<20;j++){
如果(j==10)printf(“\n\t”);
printf(“%d:%f,”,j+1,已排序[j]);
}

Idd@Ronald这是解决方案的一部分

memcpy(Sorted, Array, sizeof(float)*MaxDistArray);

thx!

您遇到了什么问题?您能给我们看一个吗?并告诉我们您给出了什么输入,以及该输入的预期和实际输出。哦,您可能应该这样做。请密切注意最后一个问题(计数)参数和它应该是什么。您只复制一个值;如果将
sizeof(float)
与要复制的浮点数相乘,您可能会得到更好的结果。“不起作用”不是问题。