The following code returns the error: Expression must have pointer-to-object type. somehow the problem lies in the way I reference the parameters A, B and out which each point to a 2D array. Any help would be much appreciated.
The goal is to multiply two arrays.
#include <stdio.h>
void matrixmul(const float *A, const float *B, int m, int n, int k, float *out)
{
float value = 0.0;
int x, y, z;
for (x = 0; x < k; x++) {
for (y = 0; y < m; y++) {
for (z = 0; z < n; z++) {
float product = A[y][z] * B[z][y];
value = value + product;
printf("%lf", value);
}
out[y][x] = value;
value = 0;
}
}
}
int main(void) {
float a[2][3] = {
{ 1.0,2.0,1.0 },
{ 3.0,4.0,1.0 }
};
float b[3][1] = {1, 2, 3};
float array[2][1];
matrixmul((float *) a, (float *) b, 2, 3, 1, (float *) array);
return 0;
}
(float *) a) -- you know you are doing something wrong...ais Notfloat *, it isfloat (*)[3]. The types are not compatible.