0

everybody, I'm newbie in C, I'm trying to build a programme to calculate the matrix, so here is my source:

#include <stdio.h>
#include <stdlib.h>

void f1(double *p, double *n, double *m, int qntF, int qntS) {
    int i,j;

    for(i=0; i<qntF; i++){
        for (j=0; j< qntS; j++){
            m[i][j] = p[i][j] + n[i][j];
        }
    }

    for(i=0; i<qntF; i++) {
        for (j=0; j< qntS; j++) {
            printf("%f",m[i][j]);
        }
    }
}

int main() {
    int i,j;

    double mat1[3][5] = { {13.1, 5, 6.9, 23.87, 43}, 
                        {65, 17.75, 1.3, 9.12, 11},
                        {54, 3, 9.8, 23.8, 9.3} };
    double mat2[3][5] = { {11, 13, 22, 34, 65},
                        {7, 23, 90, 4, 1}, 
                        {9.3, 13.45, 23.89, 34.65, 2.96} };
    double matRes[3][5];

    f1(&mat1[0][0], &mat2[0][0], &matRes[0][0], 3, 5);
}

and I get this error:

error: subscripted value is not an array, pointer, or vector
                        m[i][j] = p[i][j] + n[i][j];
                                            ~~~~^~

Like I got it that I'm trying to put 2 dimensions array to function but I get just one dimension array with 15 items.

Sorry, I tried to find the answer here but I could'nt.

Jens
  • 69,818
  • 15
  • 125
  • 179
  • Be aware that the accepted and highly upvoted answer at the dupe is wrong (partially). – n. m. could be an AI Jan 06 '22 at 18:01
  • @n.1.8e9-where's-my-sharem. Oh, I didn't notice it when skimming the the question/answer. I will remove that from the comment. The other duplicate has a more complete answer anyway. – user17732522 Jan 06 '22 at 18:11
  • Does this answer your question? https://stackoverflow.com/questions/3911400/how-to-pass-2d-array-matrix-in-a-function-in-c?noredirect=1&lq=1 – user17732522 Jan 06 '22 at 18:11
  • 2
    Does this answer your question? [How to pass 2D array (matrix) in a function in C?](https://stackoverflow.com/questions/3911400/how-to-pass-2d-array-matrix-in-a-function-in-c) – the busybee Jan 06 '22 at 19:36

0 Answers0