The deviation function throws me the following error: "Array subscript is not an integer". If you can help me locate the cause of error I'll appreciate it.
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "stdio.h"
#include "stdlib.h"
#include <stdbool.h>
//----<< To store matrix cell cordinates >>--------------------------
struct point
{
double x;
double y;
};
typedef struct point Point;
//---<< A Data Structure for queue used in robot_maze >>---------------------
struct queueNode
{
Point pt; // The cordinates of a cell
int dist; // cell's distance of from the source
};
//----<< check whether given cell (row, col) is a valid cell or not >>--------
bool isValid(int row, int col, int ROW, int COL)
{
// return true if row number and column number is in range
return (row >= 0) && (row < ROW) && (col >= 0) && (col < COL);
}
//----------------------------------------------------------------------------
int robot_maze()
{
int solution = -1;
int ROW, COL, i,j;
Point src, dest;
scanf("%d", &ROW);
scanf("%d", &COL);
scanf("%d %d",&src.x,&src.y);
scanf("%d %d",&dest.x,&dest.y);
int arr[ROW][COL],visited[ROW][COL];
for (i = 0;i < ROW;i++)
for (j = 0;j < COL;j++)
{
scanf("%d", &arr[i][j]);
visited[i][j] = -1;
};
// check both source and destination cell of the matrix have value 0
//if (arr[src.x][src.y] || arr[dest.x][dest.y])
// return -1;
return solution;
}
The "if" statement (behind the //) should just work and enter if both values are 0. notice that I defined the 2D matrix "arr" as type int. why do I get this error?
the problem I try to solve is the "Shortest path in a Binary Maze" problem, but I got stuck at the beginning.
int arr[ROW][COL]and invisited[ROW][COL], ROW and COL need to be constants. Point 2 may not apply on your platform though, you didn't mention what compiler you use. If you don't get any compiler warnings, compile with-Wall#include <stdio.h>etc unless you are using local versions.#include "stdio.h"it is not wrong: you put that when you want to use your own library instead of the standard library. Note that#include <stdbool.h>is the usual way: did the teacher's template use the two different ways to include a library header?#ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif– Is pointless since Microsofts compiler won't ever be able to compile your code since it contains a VLA (Variable Length Array).