I have two files: mainfile.c
and kmeans.c
. I want to return the addresses of the buffers that are allocated in kmeans.c
back to mainfile.c
. The following is the process:
kmeans.c
void kmeans(int *cluster_assign, int *cluster_size,){
cluster_assign = malloc(1000 * sizeof(int));
cluster_size = malloc(5 * sizeof(int));
// Some operations on both buffers
return cluster_assign, cluster_size // <<<< Here I want to return the address of both buffers to main
}
mainfile.c
int main(){
int *cluster_size = NULL;
int *cluster_assign = NULL;
kmeans(cluster_centers, cluster_size);
// Here, I don't know how to acquire the addresses that were allocated in kmeans(...)
return 0;
}
As you can see, if I don't return the addresses from kmeans.c
, I cannot proceed in mainfile.c
. I tried many ways including arrays of pointers but it was wrong. Any help is apprciated.