-1

I am trying to call a function in the following way: Before int main:

int matrixCheck(int matrix[][LEN] , int j , int i);

Call in the main:

flag =  matrixCheck(matrix[][LEN] , int j , int i);

The function itself:

int matrixCheck(int array[][LEN] , int j , int i)

and I am receiving the following error error: syntax error before ']' token (The call in the main)

There is no error before the call because it has only the following code before it.

int matrix[][LEN] = {{16,2,3,13},{5,11,10,8},{9,7,6,12},{4,14,15,1}};
int i = 0, j = 0;
int flag = 0;

Anyone has any idea why this happens?

Clifford
  • 88,407
  • 13
  • 85
  • 165
SDSDFsafad
  • 39
  • 1
  • 1
  • 6
  • 1
    The first argument is wrong, then you call it with to few arguments. – Some programmer dude Feb 06 '16 at 15:22
  • 2
    And if that's how you try to call your function, you need to check out [The Definitive C Book Guide and List](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) for a beginners book, and start all over from the beginning again. – Some programmer dude Feb 06 '16 at 15:28
  • Argument list in your "call in the main" makes no sense syntactically. Get yourself a C tutorial to see how a function call is supposed to look in C. – AnT stands with Russia Feb 06 '16 at 18:02

4 Answers4

1

The compiler says there is syntax error because there is syntax error.

The first argument for calling matrixCheck should be matrix with no extra [] and other junks.

Junk int before second and third arguments should also be removed.

MikeCAT
  • 73,922
  • 11
  • 45
  • 70
1

The call should be just:

flag =  matrixCheck( matrix, j, i ) ;

You do not specify data type or array dimensions of arguments in the function call; only in the definition or declarations.

Clifford
  • 88,407
  • 13
  • 85
  • 165
0

I'm not sure what the function does, so I'll make it print the first value of the first group in the array, then it will print the value of j and i.

After function exit, the value of flag will be printed.

I'm not sure if you know how to use a debugger, but if you don't, then at least make use of the printf statement to print out the numeric variables so you can understand how they are processed. See my code:

#include <stdio.h>
#define LEN 50

int matrixCheck(int array[][LEN] , int j , int i){
    printf("array[0][0]=%d,  i=%d, j=%d\n",array[0][0],i,j);
    return 1;
}

int main(){
    int matrix[][LEN] = {{16,2,3,13},{5,11,10,8},{9,7,6,12},{4,14,15,1}};
    int i = 17, j = 18;
    int flag = 0;
    flag =  matrixCheck(matrix,j,i);
    printf("flag=%d\n",flag);
    return 0;
}
Mike -- No longer here
  • 2,064
  • 1
  • 15
  • 37
  • P.S. I know 50 is an overkill for matrix length, but Its better to allocate just a bit extra than to under-allocate, only to end up with a segmentation fault. – Mike -- No longer here Feb 06 '16 at 17:14
  • A debugger will be of no use to him unless he can get the code to compile, and although your code will compile, and may serve as an example, you have not really explained *why* the code in the question does not, which is what the question is about. – Clifford Feb 06 '16 at 18:13
-3

I don't know what the function does but you can try with int array[][] that is the same like int **array -> so a pointer for a two dimensional array.

lukkkkkas
  • 61
  • 1
  • 2
  • as first argument for the function – lukkkkkas Feb 06 '16 at 16:57
  • That is not an answer to the question, and if mentioned at all should be a comment not an answer. A valid answer would be to address the syntax error in the function call. However `int**` has no dimension information `int matrix[][LEN]` is necessary in order to know the span of the first dimension elements. – Clifford Feb 06 '16 at 18:03
  • 1
    Firstly, `int array[][]` is invalid in C. Secondly, a built-in 2D array in C is *not* even remotely the same as "pointer to pointer". – AnT stands with Russia Feb 06 '16 at 18:04