Language: C++

#include <stdio.h>
#include <stdlib.h>

int map[2001][2001];
struct point {
  int x;
  int y;
};
struct point target;

//functions
int equalPoint(struct point p1, struct point p2);
struct point intoMap(int x, int y);
void rooting(struct point p1, struct point p2, int **map);
struct point getFree(int sx, int sy, struct point now_point, int **map);
void print_point(struct point p);
//-------------------------------------------
int main()
{
  int **map = malloc(sizeof(int*)*2001);
  
  int sx, sy, tx, ty;
  scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
  struct point p1 = intoMap(sx, sy);
  struct point p2 = intoMap(tx, ty);
  int i, j;
  for (i = 0; i < 2001; i++) {
    map[i] = malloc(sizeof(int)* 2001);
    for (j=0; j < 2001; j++) {
      map[i][j] = 0;
    }
  }


  rooting(p1, p2, map);
  rooting(p2, p1, map);
  rooting(p1, p2, map);
  rooting(p2, p1, map);


}
//----------------------------------------
int equalPoint(struct point p1, struct point p2)
{
  if (p1.x == p2.x)
    if (p1.y == p2.y)
      return 1;
  return 0;
}
void print_point(struct point p)
{
  printf("---print_point: x:%d, y:%d\n", p.x, p.y);
}
void rooting(struct point p1, struct point p2, int **map)
{
  target = p2;

  int i, j ;
  int sx = p2.x - p1.x;
  int sy = p2.y - p1.y;

  struct point now_point = p1;
  map[p1.x][p1.y] = 1;
  while (equalPoint(now_point, p2) == 0) {
    //    printf("sx:%d, sy:%d\n", sx, sy);
    now_point = getFree(sx, sy, now_point, map);
    sx = p2.x - now_point.x;
    sy = p2.y - now_point.y;
  }
  map[p1.x][p1.y] = 0;
  map[p2.x][p2.y] = 0;
    
  printf("\n");
}

struct point intoMap(int x, int y)
{
  struct point ans;
  ans.x = x + 1000;
  ans.y = y + 1000;
  return ans;
}

struct point getFree(int sx, int sy, struct point now_point, int **map)
{
  int fu, fr, fl, fd;
  fu = fr = fl = fd = 0;

  switch(now_point.x) {
    case 0: fl = -1; break;
    case 2000: fr = -1; break;
  }
  switch(now_point.y) {
    case 0: fd = -1; break;
    case 2000: fu = -1; break;
  }
  //-------------端っこチェック------------------------------
  
  //右左のチェック  
  if (fl != -1) {
    if (map[now_point.x-1][now_point.y] == 1) {
      fl = -1;
    }
  }
  if (fr != -1) {
    if (map[now_point.x+1][now_point.y] == 1) {
      fr = -1;
    }
  }
  //上下のチェック
  if (fu != -1) {
    if (map[now_point.x][now_point.y+1] == 1) {
      fu = -1;
    }
  }
  if (fd != -1) {
    if (map[now_point.x][now_point.y-1] == 1) {
      fd = -1;
    }
  }
  

  
  int box[4];
  box[0] = fu;
  box[1] = fl;
  box[2] = fd;
  box[3] = fr;
  

  //判定  X軸方向
  if (sx != 0) {
    if (box[2*(sx > 0)+1] == 0) {
      struct point ret = {
        .x = now_point.x + ((sx > 0)? 1 : -1),
        .y = now_point.y,
      };
      map[ret.x][ret.y] = 1;

      if (sx > 0) {
	printf("R");
      } else {
	printf("L");
      }
	  
      return ret;
    }
  }

  //判定　Y軸方向
  if (sy != 0) {
    if (box[2*(sy < 0)] == 0) {
      struct point ret = {
        .x = now_point.x, 
        .y = now_point.y + ((sy > 0) ? 1 : -1),
      };
      map[ret.x][ret.y] = 1;
      if (sy > 0) {
	printf("U");
      } else {
	printf("D");
      }
      
      return ret;      
    }
  }

  int i;
  for (i = 0; i < 4; i++) {
    if (box[i] == 0) {
      if (i % 2 == 0) {
        struct point ret = {
          .x = now_point.x, 
          .y = now_point.y + (( i==0 )? 1 : -1),
        };
        map[ret.x][ret.y] = 1;
	switch(i) {
	case 0: printf("U");  break;
	case 1: printf("L");  break;
	case 2: printf("D");  break;
	case 3: printf("R");  break;
	}
	
        return ret;
      } else {
        struct point ret = {
          .x = now_point.x + ((i==3) ? 1 : -1), 
          .y = now_point.y ,
        };
        map[ret.x][ret.y] = 1;
	switch(i) {
	case 0: printf("U");  break;
	case 1: printf("L");  break;
	case 2: printf("D");  break;
	case 3: printf("R");  break;
	}
        return ret;
      }
    }
  }
  printf("last hit\n");
}




Compiler output:
a.cc: In function 'int main()':
a.cc:20:21: error: invalid conversion from 'void*' to 'int**' [-fpermissive]
   20 |   int **map = malloc(sizeof(int*)*2001);
      |               ~~~~~~^~~~~~~~~~~~~~~~~~~
      |                     |
      |                     void*
a.cc:28:20: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   28 |     map[i] = malloc(sizeof(int)* 2001);
      |              ~~~~~~^~~~~~~~~~~~~~~~~~~
      |                    |
      |                    void*
a.cc: In function 'point getFree(int, int, point, int**)':
a.cc:202:1: warning: control reaches end of non-void function [-Wreturn-type]
  202 | }
      | ^