Thread: problem with mulitdimensional array as function arguements

1. problem with mulitdimensional array as function arguements

This is the problem statement for this assignment:

As warm-up, write a program that displays the sum and average of both the rows and columns of a
rectangular double array named table. Do not use a global: declare table in main. Define table’s
dimensions statically using the preprocessor, defaulting to 5 × 3. Your solution must include three
I suggest this signature for sumAveRow: sumAveRow(int r, double t[][COLS], double* sum, double*
average).

here is my code so far:
Code:
```#include <stdio.h>

#define COLS 3
#define ROWS 5

void sumAveRow(int r, double t[][COLS], double* sum, double* average);
void sumAveCol(int c, double t[][COLS], double* sum, double* average);
void readTable(int r, int c, double t[][COLS]);

int main() {

double table[ROWS][COLS];
double sum, average;
/* get inputs and store in table */

sumAveRow(ROWS, table[], &sum, &average);
return (0);
}

void readTable(int r, int c, double t[][COLS]) {

int i = 0;
int j = 0;
double data = 0;

while ( i > ROWS) {
printf("For row %d,", i);
while ( j < COLS ) {
printf("    enter a double: ");
scanf("%lf", &data);
t[i][j] = data;
j = j + 1;
}
i = i + 1;
j = 0;
}
}

void sumAveRow(int r, double t[][COLS], double* sum, double* average) {

int i = 0;
int j = 0;
sum = 0;
average = 0;
for (i = 0; i < r; i++) {
*sum = t[i][j];
}
*average = (*sum / r);
printf("Row %d:  Sum = %.2lf; Average = %.2lf", i, *sum, *average);
}```
I know it's not complete, but my real concern is that I keep getting syntax errors in the function calls for readTable and sumAveRow:
error: syntax error before ']' token. What can I do to fix this?

2. For starters, you'd want to call your functions like this.
Code:
```        readTable(ROWS, COLS, table);
sumAveRow(ROWS, table, &sum, &average);```
Then,
Code:
```        while ( i < r) {
printf("For row %d,", i);
while ( j < c ) {```
And
Code:
```        *sum = 0;
*average = 0;```
Then, I think you'd have better luck with a function like this:
Code:
```void sumAveRow(int r, int c, double t[][COLS], double* sum, double* average)
{
int i;
*sum = 0;
*average = 0;
for ( i = 0; i < c; i++ )
{
*sum += t[r][i];
}
*average = *sum / c;
printf("Row %d:  Sum = %.2lf; Average = %.2lf", r, *sum, *average);
}```
Which of course means you'd call the function like this.
Code:
`   sumAveRow(0, COLS, table, &sum, &average);`