-1

I saw there are a lot of articles about memcpy but I can't find the solution for my problem. Can somebody see why the copy action doesn't work?

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]);
}
krlzlx
  • 5,752
  • 14
  • 47
  • 55
NickDR92
  • 11
  • 5
  • 2
    What *is* the problem you are having? Can you please show us a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve)? And also tell us what input you give, and the expected and actual output from that input. – Some programmer dude Dec 05 '17 at 13:34
  • 1
    Oh and you probably should [read a `memcpy` reference](http://en.cppreference.com/w/c/string/byte/memcpy). Pay close attention to the last (the `count`) argument and what it is supposed to be. – Some programmer dude Dec 05 '17 at 13:35
  • 5
    You only copy a single value; If you multiply the `sizeof(float)` with the number of floats you'd like to copy, you might get better results. – Ronald Dec 05 '17 at 13:36
  • "Does not work" is not a question. –  Dec 05 '17 at 14:57

1 Answers1

1

Idd @Ronald that was part of the solution

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

thx!

NickDR92
  • 11
  • 5