title: How to insert distinct elements into an array?
body: <p>I am trying to insert distinct elements into a matrix. To do so I create an array of [rows x columns] dimension and place there each element I insert into the matrix and right after that read the array and if an element of the matrix is the same as one in the array make the user reintroduce the <code>[m][n]</code> element into the array. But doing so this doesn't work the way I expected and also looks a bit messy; how can it be more "simple"?</p>
  
  <pre><code>void rellenarMatriz(int **a, int f, int c) {
  
      int i, j, aux, k, l;
  
      for(i = 0; i &lt; f; i++) {
  
          for(j = 0; j &lt; c; j++) {
  
              //Introducir numero
              printf("    [%d][%d]&gt; ", i+1, j+1);
              scanf("%d", &amp;a[i][j]);
  
              //Comprobar que ese elemento no está en la matriz  
              contieneElemento(a, i, j);   
          }
  
          printf("\n");
      }    
  }
  </code></pre>
  
  <p><strong>NOTE</strong>: This is not homework, I am trying to learn on my own.</p>
  
  <p>Solution?</p>
  
  <pre><code>void contieneElemento(int ** a, int ff, int cf) {
  
      int i, j;
  
      for(i = 0; i &lt;= ff; i++) {
  
          for(j = 0; j &lt;= cf; j++) {
  
              printf("[%d][%d]&gt;\n", i + 1, j + 1);
  
              do {
  
                  printf("&gt; Elemento repetido.\n");
                  printf("   *[%d][%d]&gt; ", ff + 1, cf + 1);
                  scanf("%d", &amp;a[ff][cf]);
              } while(a[i][j] == a[ff][cf]);
          }
      }  
  }
  </code></pre>