I wonder what this problem is :error C2664: 'mine' : cannot convert parameter 1 from 'int [100][100]' to 'int'
1> There is no context in which this conversion is possible
Here is my full program.

#include <stdio.h>
int mine(int ,int,int);
int main()
{
	int m,n;
	int i,j;
	int u,v;

	int input[100][100];
	int output[100][100];
	printf ("Input M,N: %d %d",m,n);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
		{
			printf("State of the [%d][%d] cell is: %d",i,j,input[i][j]);

		}
		for (u=0;u<m;u++)
		{
			for(v=0;v<n;v++)
			{
				output[u][v]=mine(input,u,v);
				printf("%d ",output[u][v]);
			}
			printf("\n");
		}





	return 0;
}
int mine(int input[3][4],int r,int c)
{
	int ans,i,j;
	for(i=r-1;i<=r+1;i++)
	{
		for(j=c-1;j<=c+1;j++)
		{
			ans+=input[i][j];


		}
	}
		ans-=input[r][c];
	return ans;
}

Edited 5 Years Ago by Narue: Added code tags

int mine(int ,int,int);

Your prototype clearly says that the first argument is int . Maybe you shouldn't lie to the compiler, it can get confused easily. ;)

Your prototype clearly says that the first argument is int . Maybe you shouldn't lie to the compiler, it can get confused easily. ;)

I tried output[v]=mine(input[m][n],u,v);
Then it print out a whole bunch like
warning C4700: uninitialized local variable 'n' used
1>c:\users\viet\documents\visual studio 2010\projects\testapp\testapp\test.cpp(11): warning C4700: uninitialized local variable 'm' used
1>test.obj : error LNK2019: unresolved external symbol "int __cdecl mine(int,int,int)" (?mine@@YAHHHH@Z) referenced in function _main
1>C:\Users\Viet\Documents\Visual Studio 2010\Projects\Testapp\Debug\Testapp.exe : fatal error LNK1120: 1 unresolved externals

Change the prototype, not the call:

int mine(int ,int,int);

should be

int mine(int[][100],int,int);

And to waylay your next question, do the same thing with the definition:

int mine(int input[][100],int r,int c)
{
   ...

Thank you very much,it works now,Can you explain why we have to use int mine(int[][100],int,int); instead of int mine(int[100][100],int,int);

Can you explain why we have to use int mine(int[][100],int,int); instead of int mine(int[100][100],int,int);

The size of the first dimension is ignored for reasons that you'll learn later. Because of this you can omit the size, but if you want you can keep it. However then the declaration would be misleading because you aren't limited to passing arrays where the first dimension is 100:

#include <stdio.h>

void foo(int array[100][5])
{
    int i, j;
    
    for (i = 0; i < 2; i++) {
        for (j = 0; j < 5; j++)
            printf("%2d", array[i][j]);
            
        puts("");
    }
}

int main(void)
{
    int a[2][5] = {
        {1, 2, 3, 4, 5},
        {6, 7, 8, 9, 0},
    };
    
    /* Aroo? But foo() expects an array of int[100][5]! */
    foo(a);
    
    return 0;
}

I tried output[v]=mine(input[m][n],u,v);
Then it print out a whole bunch like
warning C4700: uninitialized local variable 'n' used

first thing,
Initialise the variables that you have declared. If you don't, then they contain garbage values.

Edited 5 Years Ago by aero31aero: n/a

first thing,
Initialise the variables that you have declared. If you don't, then they contain garbage values.

Not necessary if the first thing you do with any variable is read or load a value into it.

This article has been dead for over six months. Start a new discussion instead.