I want to copy the duplicates of one array into another array. src[]={1, 3, 5, 3, 1} -> dst[]={1, 3}
This is my approach:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
size_t copy_duplicates(int dst[], const int src[], size_t len) {
size_t lengthdst = 0;
for(size_t i =0; i < len -1; i++){
for(size_t d = i +1; d < len; d++){
if(src[i] == src[d]){
dst[i]=src[i];
lengthdst++;
}
}
}
return lengthdst;
}
int main(void){
int i;
int dst[?lenghtdst];
const int scr[]={6, 4, 6, 4};
copy_duplicates(dst, scr, 4);
while(i < 2){
printf("%d", dst [i]);
i++;
}
}
The first function works, but I don't know how I can get the length of dst in the main function. To get the length I already need dst. I think I have to change the return value. I've tried a few other returns but nothing works.