Being a beginning (and when I say beginning, I mean that this is my first program apart from the little "Hello World" ones) C++ programmer, theirs probably a very obvious flaw in what I've written so far, but here is what I've written:
#include <iostream>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
int groundArr[10][10];
int mapGen(groundArr[10][10]);
int main(groundArr[10][10])
{
mapGen(groundArr[10][10]);
int i;
int j;
i = 0;
j = 0;
for (j<10,j++)
{
for (i<10,i++)
{
if (groundArr[i][j] = 1)
{
if (i == 1)
{
cout << ".\n";
}
}
}
}
}
int mapGen(groundArr[10][10])
{
int i;
int j;
i = 0;
j = 0;
for (i<10,i++)
{
for (j<10,j++)
{
groundArr[i][j] = 1;
}
}
}
The error that pops up says "Expected ',' or ';' before '{' token".
It's talking about the 10th line of code, but I can't find the error anywhere. Any help is greatly appreciated.
for (initialization; condition; iteration)
{
//Stuff.
}
Also, your main function cannot take anything as an argument except argc or argv, which are int and char**, respectively.
Also, your function definitions are off. You're supposed to list the type of the argument being passed to the function as well as the name.
int mapGen(int** groundArr);
EDIT: The above is wrong. I use way to many pointers in my programming, really. :) It should've been (as Disch pointed out and as I realized while my browser was refreshing): int mapGen(int groundArr[][10]);
Thanks Albatross!! I made those changes, and it finally compiled without errors, but when I ran the compiled program, it froze. The little window that says "<program name> has stopped working" popped up and closed the program. Anybody know of a reason this may have happened?
This is wrong. Pointers to Pointers are not the same thing as a 2D array.
the right way to do it would be:
int mapGen(int groundArr[][10])
But note:
- this would not work with pointer to pointer arrays (ie: nested new arrays)
- this would not work with arrays that have a different width (ie: int foo[10][9]; would not be able to be passed)
You're also passing the array incorrectly:
1 2 3 4
int main(groundArr[10][10]) // main does not take groundArr as a parameter
{
mapGen(groundArr[10][10]); // this does not pass the array, it passes a single element of the array
// (and an invalid out-of-bounds element, at that)
The correct way would be:
1 2 3
int main()
{
mapGen(groundArr);
EDIT: I guess Albatross pointed out main() already XD whoops