0

I am not able to pass array arr in my function search it shows the error as below,

prog.cpp: In function ‘int main()’:
prog.cpp:28:39: error: no matching function for call to ‘search(int [m][n], int&, int, int)’
          else count=search(arr,i,0,n-2);
                                       ^
prog.cpp:4:5: note: candidate: int search(int (*)[100], int, int, int)
 int search(int arr[][N],int i,int l,int r){
     ^
prog.cpp:4:5: note:   no known conversion for argument 1 from ‘int [m][n]’ to ‘int (*)[100]’
In file included from /usr/include/c++/5/algorithm:62:0,

My Code as below,

#include<bits/stdc++.h>
#define N 100
using namespace std;
int search(int arr[][N],int i,int l,int r){
    if(r>=l){
        int q=(l+r)/2;
        if(arr[i][q]==0 and arr[i][q+1]==1) return q;
        if(arr[i][q+1]==0) search(arr,i,q+1,r);
        else search(arr,i,l,q-1);
    }
}
int main()
 {
    //code
    int t;
    cin>>t;
    while(t--){
        int m,n,count=0,min=41,row=0;
        cin>>m>>n;
        int arr[m][n];
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++) 
            cin>>arr[i][j];

        for(int i=0;i<m;i++){ 
            if (arr[i][n-1]==0) count=n;
            else if(arr[i][0]==1) count= 0;
            else count=search(arr,i,0,n-2);
            if(count<min){
                min=count;
                row=i;
            }
       }
      cout<<row<<endl;  
    }
    return 0;
}

Thanks in advance.

sharma.37
  • 67
  • 1
  • For information, in your code, you have no guarantee that `n == N`. – Fareanor Feb 19 '20 at 13:01
  • `cin>>m>>n; int arr[m][n];` is invalid C++, using VLA extension. use `std::vector` instead. That should fix your issue to pass argument to function. – Jarod42 Feb 19 '20 at 13:01

0 Answers0