Not declared in this scope PLEASE HELP

I need to copy a two dimensional array to a function but its size is variable. How can i do it? This is what i tried:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <fstream>

using namespace std;
             
int check(int arr[N][N],int a, int b){
    while (arr[a][b]==0){
        arr[a][b]=1;
        check(arr,a,b+1);
        check(arr,a+1,b);
        check(arr,a,b-1);
        check(arr,a-1,b);
        }
        }

int main(){
    ifstream in ("in.txt");
    ofstream out ("out.txt");
    int N,i,j,islands=0,a;
    in>>N;
    int arr[N][N];
     for (i=0;i<N;i++){
         for (j=0;j<N;j++){
             in>>a;
             arr[i][j]=a;
             }
             }
    for (i=0;i<N;i++){
        for (j=0;j<N;j++){
            if (arr[i][j]==0){
               islands+=1;
               check(arr,i,j);
               }
            }
            }
    out<<islands<<endl;
    
    in.close();
    out.close();
    
    return 0;
}


Thanks in advance

Andreas
out<<islands<<endl; needs to be cout<<islands<<endl;

bah, nevermind output to file. what is the exact error?
Last edited on
You need to tell the function the second depth of your array.
Ie.
int check(int arr[] [x]) where x is the depth of the two dimensional array.

If you need the function to accept an array that is variable in both dimensions
I suggest using a single dimensional array and the width and height of the array:

int check(int arr[], int x,int y)

Then to access specific values you use the formula:

arr[x+y*x] which is equal to arr[x][y]
Thank you BlackSheep, you helped me a lot. Problem solved.
Topic archived. No new replies allowed.