Index of an array

Hi All,

I have a 2d array and I am trying to get the index of a specific element. Actually, it is enough if i can get the second index.

Here is my function:

int indexFinder(int SIZE1, int SIZE2, int array, int number, int index){

for(int i = 0; i < SIZE1; i++){
for(int j = 0; j < SIZE2; j++)
{
if(array[i][j] == number){
return j;
break;
}
}
}

}

Where is the mistake here?

Thanks-
It is obvious that the mistake is in the incorrect declaration of the array in parameters

int indexFinder(int SIZE1, int SIZE2, int array, int number, int index){

array is declared as a scalar object of type int.
Last edited on
This is what I got lastly. There is still something wrong:

int indexFinder(int SIZE1, int SIZE2, int array[], int number){
for(int i = 0; i < SIZE1; ++i){
for(int j = 0; j < SIZE2; ++j)
{
if(array[i][j] == number) return j;
}

return -1;
}
}
The parameter value 'array' should be in the form:

int **array, int *array[], or int array[][]

EDIT:
Not sure about the last option there, but try it and see.
Last edited on
It works, thanks!
Topic archived. No new replies allowed.