-
Errors!
PHP Code:
#include <iostream.h>
void draw_map(int x, int y)
{
int map[x][y];
int temp_x, temp_y;
for(temp_x=1;temp_x < x; x++)
{
for(temp_y = 1; temp_x < y; y++)
{
map[x][y]=0;
}
}
}
int main()
{
draw_map(50,50);
return 0;
}
Ive got a problem with my code, its the 2dimentional array part. Can anyone help?
-
Well, just at a glance...
The array is local to the function. You should pass the array from main() if you want to keep it; otherwise, it gets destroyed when the function goes out of function.
Also, remember that the array starts at [0], so your initialization should look like this:
for(temp_x=0;temp_x < x; x++)
not: for(temp_x=1;temp_x < x; x++)
-
I think you did a typing mistake:
Code:
for (temp_y = 1; temp_x <y; y++);
i think you meant
Code:
for (temp_y = 1; temp_y <y; y++)'
If im wrong just tell me
-
Nope :(
Well Ive chnaged both of those, and tried defining it global but I still get the same errors
theres somthing wrong with this line
int map[x][y];
-
> int map[x][y];
Array sizes should be constant expressions (these are variables)
-
I believe if you're using a variable to define the array size you have to use the new operator to create it.
-
hello friend
u must know the rule for array
use constants or constant variables in side the array index