I'm not a newby, but this has me feeling like one. As long as I have an array with hard coded values I'm fine, but the moment I try to dynamically allocate my array the thing goes tits up.
I'm trying to translate the old DOS game "Robotfindskitten" to PDCurses (I know it's been done, but it doesn't work for me), and I get the whole thing to work until I change the line:
Code:
int screen[80][24];
to
Code:
int screen[COLS][LINES];
at which point I get the error:
Code:
error: variable-size type declared outside of any function
Okay, so I move the screen variable declaration inside the main function and pass by reference to the only function that needs it. Looks good except for when I run it. Now I'm getting a segfault at the line :
Code:
for (c = 0; c <= COLS; c++)
{
for (c2 = 0; c2 <= LINES; c2++)
{
screen[c][c2] = EMPTY;
}
}
...when c=0 and c2=11. What?
I feel like I've delt with this before, but I can't figure out how I fixed it. It used to be that you could declare an int** and use that to pass a 2D array, but that seems to be disabled now. What is going on?