0

I got an unexpected error while doing a function call in C using the array, I know a little bit of C and I don't understand how I can fix it. The code of the main function is attached below.

void sum_matrices (int m1[][NUM_COLS], int m2[][NUM_COLS], int num_rows, int result[][NUM_COLS]);
void print_matrix (int m[][NUM_COLS], int num_rows);
void print_array (int a[], int len);

int main(void) {

    int my_matrix_1[][NUM_COLS] = {{1, 5, 3, 4, 2},
                                   {7, 1, 4, 1, 7},
                                   {6, 9, 2, 0, 5}};
    int my_matrix_2[][NUM_COLS] = {{7, 8, 3, 3, 4},
                                   {1, 3, 7, 8, 2},
                                   {1, 3, 5, 6, 0}};
    int num_rows = 3;
    int result[num_rows][NUM_COLS]; // finish this line of code to create the result matrix to pass to sum_matrices

    // add call to sum_matrices to add my_matrix_1 and my_matrix_2

    sum_matrices (my_matrix_1[][NUM_COLS], my_matrix_2[][NUM_COLS], num_rows, result[][NUM_COLS]);

    print_matrix(my_matrix_1, num_rows);
    printf("\n");
    print_matrix(my_matrix_2, num_rows);
    printf("\n");
    print_matrix(result, num_rows);
    return 0;
}
2
  • 2
    Are you allowed to tell us what the error is? Commented Feb 24, 2019 at 21:12
  • 1
    Looking at that code, you're probably getting many more errors than just one as you say. Is this your full code? What is the error you have trouble understanding/fixing? Commented Feb 24, 2019 at 21:15

1 Answer 1

2

Your "call" of function sum_matrices within function main...

sum_matrices (my_matrix_1[][NUM_COLS], my_matrix_2[][NUM_COLS], num_rows, result[][NUM_COLS]);

is a mixture of a forward declaration of a function and a function call, but neither of both is complete or allowed at this position in that form.

To call the function, write...

sum_matrices (my_matrix_1, my_matrix_2, num_rows, result);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.