I am struggling at the following task:
Write a function called copy which takes the following parameters:
-Two integer arrays
-The size of the two arrays as an integer
-A threshold value as an integer
Your function should copy the values of the first array into the second array but ignore values above the given threshold.
I always get only 0 0 0 0 0 as output with my function. Does anybody now how I can fix this?
Code:
int copy(int* arr1, int* arr2, int length, int d) {
for (int m=0; m< length;m++){
int min= arr1[m];
for( int i=m+1; i< length; i++){
if (min>arr1[i]){
arr1[i]=arr1[i-1];
}
else
min=min;
}
arr2[m] = min;
}
for (int n=0; n< length;n++){
if (arr2[n] > d)
arr2[n]=0;
else
arr2[n]=arr2[n];
}
}