title: Can't do all possible moves of a Horse in a Chess table
body: <p><strong>UPDATE:</strong> Thanks a lot M Oehm for your awesome answer, really helped me a lot. That struct pos moves is really helpful, haven't studied it yet on class. Im working on a fully solution of my code adding yours as a bone on the programs skeleton. Already fixed the problem of updating fila and columna, the random choice and the switch from 0 to 7 without the ' ' because they're not characters as you and davidc pointed. My program still have some problems which im working on before posting the fully operational program here. I'll update the code tomorrow if not today. Thank you all for your comments and solutions, and M oehm for the time you spent making that wonderful answer.
  <br>------------------------------------------------------------------------------------------------------------------------------------
  <br>
  <strong>UPDATE 2:</strong> Finnished it, made some  little changes on M Oehm code and instead of putting manually the first location of the horse i used my previous PosicionCaballo(). Had to delete the code of the MoverCaballo() which had a Switch with 8 possible moves which was set by a random number because i couldn't make it work (i guess the main problem was that part because already was a mess). <br><br>Now the program with the code below should ask the user for the initial position of the horse, after that the screen will print a 10x10 table filled with 0's (free spaces), fill it with 1's (taken spaces which did the horse moving randomly) and when it finnishes display a message on how many positions did it take.</p>
  
  <pre><code>COORD cxy;
  #define posicion(x,y) {(cxy.X)= (x);(cxy.Y)= (y); SetConsoleCursorPosition((GetStdHandle(STD_OUTPUT_HANDLE)), (cxy) );}
  
  int ajedrez[10][10];
  int fila, columna;
  
  void GenerarTablero(int m[10][10]){
      int i, j;
      for (i = 0; i &lt; 10; i++){
          for (j = 0; j &lt; 10; j++){
              m[i][j] = 0;
          }
      }
  }
  </code></pre>
  
  <p>GenerarTablero makes the chess board and fills it with 0's.
  <br>
  Global are fila (row) and columna (column) the parts of the ajedrez[10][10]<br>
  ajedrez[10][10] is the chess table in a 10x10 size.</p>
  
  <pre><code>void PosicionCaballo(int m[10][10]){
      printf("Fila: ");
      scanf_s("%d", &amp;fila);
      printf("Columna: ");
      scanf_s("%d", &amp;columna);
      printf("\n");
  
      m[fila][columna] = 2;
      system("cls");
  
  }
  </code></pre>
  
  <p>PosicionCaballo does ask the user for the initial position of the horse and puts the horse on the table.<br>
  Example: Row: 5 Column: 5</p>
  
  <pre><code>int horse(int y, int x)
  {
      int visited[SIZE][SIZE] = { { 0 } };
      int count = 0;
  
      if (on_board(y, x) == 0) return -1;
  
      /* Set starting position */
      visited[y][x] = 1;
  
      while (1) {             /* Infinite loop - must use break */
          int poss[8];        /* Possible moves */
          int nposs = 0;      /* Actual length of poss */
          int i, k = 1;
  
          for (i = 0; i &lt; 8; i++) {
              int xx = x + moves[i].x;
              int yy = y + moves[i].y;
  
              if (on_board(yy, xx) &amp;&amp; visited[yy][xx] == 0) {
                  poss[nposs++] = i;
              }
          }
  
          /* No more valid moves: return */
          if (nposs == 0){
              posicion(0, 11);
              printf("El tablero se ha bloqueado con ");
              return count;
          }
  
          /* pick one of the valid moves */
          i = poss[rand() % nposs];
          x = x + moves[i].x;
          y = y + moves[i].y;
  
          /* update horse's position */
          visited[y][x] = 1;
          count++;
  
          /* print position */
  
          posicion(y, x);
          printf("1");
  
      }
  
      return -1;      /* Should never be reached */
  }
  
  void MostrarMapa(int m[10][10]){
      int i, j;
      for (i = 0; i &lt; 10; i++){
          for (j = 0; j &lt; 10; j++){
              printf("%d", ajedrez[i][j]);
          }
          printf("\n");
      }
  }
  </code></pre>
  
  <p>MostrarMapa only prints the chess table on the screen.
  <br></p>
  
  <pre><code>int main(void){
  
      int n;
  
      srand(time(NULL));
      GenerarTablero(ajedrez);
      PosicionCaballo(ajedrez);
      MostrarMapa(ajedrez);
      n = horse(fila, columna);
      posicion(31, 11);
      printf("%d movimientos\n", n);
  
  
  
      getch();
      return 0;
  }
  </code></pre>
  
  <p>and then my main which im using all the functions stated upside.<br>
  Thank you very much in advance for your help guys :).<br></p>