While compiling the below code, I am getting warning:
warning: assignment from incompatible pointer type
maze->mazeValue = mazeValue;
This is the maze solving code. Have tried it but couldn't identify the issue. If I change
char mazeValue[BUFFERSIZE][BUFFERSIZE]
to char \*\* mazeValue**
, the program gets compiled the did not execute. Windows throws alert.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define BUFFERSIZE (1000)
#define MAZE_ENTRANCE '.'
struct maze {
char ** mazeValue;
int startx, starty;
int numrows;
int initdir;
};
void ReadMaze(struct maze * maze);
int main(int argc, char *argv[]) {
struct maze maze;
ReadMaze(&maze);
printf("Thanks");
//PrintStage(&maze);
return EXIT_SUCCESS;
}
/* Creates a maze from a file */
void ReadMaze(struct maze * maze) {
char buffer[BUFFERSIZE];
char mazeValue[BUFFERSIZE][BUFFERSIZE];
//char workingMaze [BUFFERSIZE][BUFFERSIZE];
//char ** map;
int rows = 0, foundentrance = 0, foundexit = 0;
int columns = 0, i = 0;
/* Determine number of rows in maze */
while ( fgets(buffer, BUFFERSIZE, stdin) ){
//puts(buffer);
columns = strlen(buffer);
/*
for(i=0; buffer[i] != '\0'; i++)
{
//printf("Row: %d\n", rows);
//putchar(buffer[i]);
//printf("\n");
mazeValue[rows][i] = buffer[i];
//putchar(mazeValue[rows][i]);
//printf("\n");
}
*/
strcpy(mazeValue[rows], buffer);
for ( i = strlen(mazeValue[rows]) - 1; isspace(mazeValue[rows][i]); --i )
mazeValue[rows][i] = 0;
/* Check for entrance and save the location if it finds */
if ( !foundentrance && rows == 0) {
i = 0;
printf("rows %d\n", rows );
printf("i %d\n", i );
while ( mazeValue[rows][i] != MAZE_ENTRANCE && mazeValue[rows][i++] ){
if ( mazeValue[rows][i] == MAZE_ENTRANCE ) {
maze->startx = i;
maze->starty = rows;
foundentrance = 1;
}
}
}
++rows;
}
maze->mazeValue = mazeValue;
maze->numrows = rows;
printf("maze->startx %d\n", maze->startx);
printf("maze->starty %d\n", maze->starty );
printf("\n");
printf("Stage 1\n");
printf("=======\n");
printf("maze has %d rows and %d columns\n\n", rows, columns);
i=0;
int j;
for(i=0; i<=rows; ++i)
{
for(j=0; j<=columns; ++j){
printf("%c", mazeValue[i][j]);
printf("%c", mazeValue[i][j]);
}
printf("\n");
}
printf("\n");
printf("foundentrance: %d\n", foundentrance);
}