I programmed some functions that use a dynamic array of
double ** array
.
But know, I want to test the results with a small array of 5 x 5 elements and use this array in the functions I coded.
My problem is that I can find no way to have a new ** use the 5 x 5 array.
Previously, I had similarities built like this:
void getSimilarities(const int sz, double **ars);
double * similarities = (double **) malloc(sample_size * sizeof(double *));
if (! similarities) {
cout << "Not enough memory!" << endl;
exit(1);
}
for(unsigned int i = 0; i < sample_size; i++) {
similarities[i] = (double *) malloc(sample_size * sizeof(double));
if(! similarities[i]) {
printf("Not enough memory.\n");
exit(1);
}
}
getSimilarities(sample_size, similarities);
And now, I'd like to try the similarities_b array:
double similarities_b[5][5] = {
{1.0, 0.0, 1.0, 1.0, 1.0},
{0.0, 1.0, 1.0, 0.0, 0.0},
{1.0, 1.0, 1.0, 0.0, 1.0},
{1.0, 0.0, 0.0, 1.0, 1.0},
{1.0, 0.0, 1.0, 1.0, 1.0}
};
double ** similarities = similarities_b;
But gcc gives this error:
error: cannot convert 'double (*)[5]' to 'double**' in initialization
I'm new to C, and don't know how to solve this.