Here is my input for this code.
1
11111111111111111111
11111111111111111111
1111S000G11111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
The problem.
When checking for char 'S' the array is showing it is finding S at element [2][7] this is obviously incorrect.
Code:
FILE *infile; // file
// If statement for opening file and error for fail.
if((infile = fopen(file, "r")) == NULL)
{
printf("Error Opening File. \n");
exit(1);
}
fscanf(infile, "%d", &num_of_mazes);
char **maze;
maze = (char **) malloc(20 * sizeof(char *));
if(maze == NULL)
{
printf("ERROR cannot be allocated");
}
for(i = 0; i < 20; i++)
{
maze[i] = (char *) malloc(20 * sizeof(char));
}
for(k = 0; k < 20; k++)
{
for(j = 0; j < 20; j++)
{
fscanf(infile, "%c", &maze[k][j]);
}
}
for(k = 0; k < 20; k++)
{
for(j = 0; j < 20; j++)
{
printf("%c", maze[k][j]);
if(maze[k][j] == 'S')
{
printf("%d %d", k, j);
}
}
}
Im not sure if I didn't allocate right.. or if my scanf is getting bugged. Anyone have any ideas?