0

I'm trying to run my code but I get 5 errors and they're all of the same kind. The first is:

note: expected 'int (*)[3]' but argument is of type 'int'

In, for example, this part of my code (it points out on the line where you see the word HERE

HERE-> int isNeighbourClose(int mat[N][M], int i, int j, int a, int b){

     int m;

     m=calcDistance(mat[i][j], mat[a][b]);
     if(m<=1)
     {
         return 1;
     }
     return 0;
   }

And the other is:

error: passing argument 1 of 'isNeighbourClose' makes pointer from integer without a cast

In, for example, this part of my code

int isCellExtreme(int mat[N][M], int i, int j){

    int a, b;
    int m;

    for(a=-1;a<=1;a++)
    {
        if((i+a>=0) && (i+a<=N))
        {
            for(b=-1;b<=1;b++)
            {
                if((j+b>=0) && (j+b<=M))
                {
                    if((a!=0)||(b!=0))
                    {
          HERE->          m=isNeighbourClose(mat[N][M], i, j, i+a, j+b);
                        if(m)
                        {
                            return 0; 
                        }
                    }
                }
            }
        }
    }
    return 1;
}

I went over this a couple of times and can't find where the problem is. Any idea where I'm mistaken?

Thanks in advance.

4
  • Is there a function prototype for that function floating around somewhere? Commented Jan 12, 2017 at 2:04
  • Hi. Which of the two functions are you talking about? Commented Jan 12, 2017 at 2:07
  • change the call in isCellExtreme to m=isNeighbourClose(mat, i, j, i+a, j+b); and see if that works better. Commented Jan 12, 2017 at 2:16
  • 1
    Thank you. It works now. Can you please explain what I did wrong with calling mat[N][M]? Commented Jan 12, 2017 at 2:23

1 Answer 1

2

When you pass mat[N][M] to isNeighbourClose, you're not passing a 2D array like you think you are. You're passing in the single element of mat at row N column M.

The function expects a 2D array, so pass the whole array:

m=isNeighbourClose(mat, i, j, i+a, j+b);

EDIT:

When you have a declaration like this:

int mat[N][M];

You're specifying the datatype and (in this case) the dimensions of the array, i.e. it says "mat is an array of N by M elements". This differs from an expression as mentioned above where mat is being used.

Sign up to request clarification or add additional context in comments.

4 Comments

I understand now. Thank you!
Wait. So when do I declare mat[N][M] and when do I omit the [N][M]?
Got it. Thank you dbush!
@FlyGuy Glad I could help. Feel free to accept this answer if you found it useful.

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.