Program with Multi-Dimensional Array

Hey guys, here I have a program that's supposed to generate a maze. It is not completely finished, and there are a few problems, but what stumps is how to pass a multi-dimensional array, edit it, and then return it.
When I compile, it usually tells me I can't convert a const *char to char in the maze gen function. Right now it tells me "cannot convert 'char (*)[(((unsigned int)(((int)num) - 1)) + 1u)]' to 'char (*)[12]' for argument '1' to 'char mazeGenerator(char (*)[12], int)'". It also does not read arr in the MazeGen function. Thanks for any help.

P.S. The woes begin at lines 24, 25, 26, etc.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <cstdlib>
using namespace std;

const int size = 12;

char mazeGenerator( char [][12], int);
void print(char [][12], int);

int main()
{
int num=12;
char arr[12][num]={"#"};
mazeGenerator(arr, num);
print(arr, num);
return 0;
}

char mazeGenerator(const char arr[][num],int num)
{
int x, y;
y=rand()%(num-2)+1;
x=1;
arr[x-1][y]=".";
arr[x][y]=".";

do 
{
int r=rand()% 4+1;
if (r=1 && y+1>0 && arr[x][y-1]="#" && arr[x-1][y+1]="#" && arr[x+1][y+1]="#" && arr[x][y+2]="#")
{
arr[x][y+1]=".";
y++;
}
else r=rand()% 4+2;
if  (r=2 && size>x+1 && arr[x+1][y]="#" && arr[x+1][y+1]="#" && arr[x+1][y-1]="#" && arr[x+2][y]="#")
{
arr[x+1][y]=".";
x++;
}
else r=rand()% 4+3;
if (r=3 && y-1>0 && arr[x][y-1]="#" && arr[x-1][y-1]="#" && arr[x+1][y-1]="#" && arr[x][y-2]="#")
{
arr[x][y-1]=".";
y--;
}
else if (x-1>0 && arr[x-1][y]="#" && arr[x-1][y+1]="#" && arr[x-1][y-1]="#" && arr[x-2][y]="#")
{
arr[x-1][y]=".";
x--;
}
else 
	while (x!=size-1)
	do 
	{
	for (int x=0; x<size; x++)
	for (int y=0; y<size; y++)
	{
		if (arr[x][y]="." && arr[x+1][y]="#" && arr[x+1][y+1]="#" && arr[x+1][y-1]="#")
		{
		arr[x+1][y]=".";
		x++
		}
	}
	}
}
while (x!=size-1)
return  arr;
}

void print (char arr[][num], int num)
{
for (int i=0; i<num; i++)
for (int j=0; j<num; j++)
{
cout << arr[i][j] <<setw (4);
if (i=size-1)
{
cout <<"\n";
}
}
}
Hah, I was just at a Stroustrup's lecture today and he brought up the crazy types of the VLA arrays in C and how they will be normal arrays when C++ gets VLAs. And there they are in your error message.

In any case, your first error is
int num=12;
which must be
const int num=12;
for the next line to compile.

There are quite a bit more errors after that, I would start by compiling a smaller program.
Last edited on
It is strange enough that you defined constant size

const int size = 12;

and at the same time you are using magic value 12 everywhere in your code as for example in the function declaration

char mazeGenerator( char [][12], int);

By the way the declaration

char mazeGenerator( char [][12], int);

does not correspond to the definition

char mazeGenerator(const char arr[][num],int num)


Last edited on
Topic archived. No new replies allowed.