Array Parameters? HELP PLEASE!

Anyone please tell me what is wrong with this code. Watched one of the youtube videos and that how they created the void function using arrays. No, I didn't copy them, but I believe void carinitialize (char carimage[arrayrowsize][arraycolumnsize]) something is wrong with this part of code. Is this not the proper way to have parameters. If not how can I fix this issue? Note: I do want a parameter in there, unless there really is no way. I know I can just not have any parameters, and then initialize all of that, but I don't want to use that approach. and I had the arrowrize and collumsize to 3 by 7. The error is on line 3 bracket in the end, right after equal sign saying expecting a expression?...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  void carinitialize (char carimage[arrayrowsize][arraycolumnsize])
{
	carimage[arrayrowsize][arraycolumnsize]={
													{'-','-','-','-','-','-','-'},
												   {'|',' ',' ',' ',' ',' ','|'},
													{'|',' ',' ',' ',' ',' ','|'}
	};
	
	int row=0;
	int col=0;
	for (row=0;row<2;row++)
	{
		for (col=0;col<3;col++)
		{
			cout<<carimage[row][col];
		
		}
	
	}

}
Last edited on
add a char before carimage [ ][ ]
Shadofiend I did that; however, it says redefinition of formal parameter carimage on sameline :(
You can't define the size of the array in the function definition. Instead, just have the declaration like this:
1
2
3
4
5
6
7
void carinitialize(char **carimage, int arrayrowsize, int arraycolumnsize) {
    // etc.
}
// or, if you prefer
void carinitialize(char carimage[][], int arrayrowsize, int arraycolumnsize) {
    // etc.
}


Also, you can't initialize carimage like the way you did in line 3, you can only do that when declaring a variable. You'll have to declare it manually, without initializer lists, as far as I know.
Ahhh!! Nice to know that :D I haven't learned about pointers yet, but will keep your second option in handy. I was doing that right now and what I have is that const char carinitialize on the global scope and then from that point onwards I will make a void function to print it out. I'm going to try this method out of yours! Appreciate it !
NT3, I got an error on your second void function without the pointers. I had an error on the second bracket saying an array might not have the elements of this type. I guess I will use another method, but thanks for your help :) especialy the initialization :)

void carinitiail (char carimage[][], int arrayrowsize, int arraycolumnsize)
Topic archived. No new replies allowed.