Have you tried to print out the values of newX and newY right before the following line:
This is the line causing your segmentation fault. The problem I saw was newX was equal to 9 so 9 + 1 would be out of bounds.Code:while (((grid[newX + 1][newY] || grid[newX - 1][newY] || grid[newX][newY - 1] || grid[newX][newY + 1]) != 1) )
Jim