In the game The Labrynth
On the input char ,I have a char **COL
After reading the inputs, I then have a test case
// Reading in
for (i = 0; i < R; i++) {
// C of the characters in '#.TC?' (i.e. one line of the ASCII maze).
scanf("%s", COL[i]); fgetc(stdin);
}
//Test Case (Also note DEBUG(…) = fprintf(stderr, …))
for (int r = 0; r < R; r++)
{
DEBUG("\n");
for (int c = 0; c < C; c++)
{
DEBUG("%c", COL[r][c]);
}
}
It works as expected, and prints out all the characters
However once I enter initNodeMap function, things get weird. I should also point out, we enter the initNodeMap immediately after coming out of the test case.
void initNodeMap(Vector *v, Node **map, char **COL, int C, int R) {
int r, c;
DEBUG("init_nodemap and last char is %c, R = %i, C = %i\n", COL[R-1][C-1], R, C);
for (r = 0; r < R; r++)
{
DEBUG("\n");
for (c = 0; c < C; c++)
{
Node *p = calloc(1, sizeof(Node));
p->r = r;
p->c = c;
//p->data = (char) COL[r][c]; // commented out
if (r == R -1) // Notice at the beginning we accessed and printed out COL[R-1][C-1]
if (c == C -1)
{/***This is where it trips a Segmentation fault when accessing COL[r][c]*/
DEBUG("\nr = %i, c = %i", r,c);
DEBUG("r = %i c = %i and last char = %c",r,c, COL[r][c]);
So unless I am mistaken, there seems to be something wrong. COL[R-1][C-1] is accessible and does not seg fault, but then seemingly for no reason, it does.
Is this a bug or am I missing something?