title: Deleting elements from a dynamic array in C
body: <p>So I am trying to make an app which will make an array of 26 values and pick random numbers to fill it, after that I have to find duplicates and  delete it.
  This is what I have done until now, the problem which I really don't understand is why it works for a size of 10 but not for any value bigger than 10.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int remove_element(int** array, int sizeOfArray, int indexToRemove)
  {
      int i;
  
      int* temp = malloc((sizeOfArray - 1) * sizeof(int));
  
      memmove(
              temp,
              *array,
              (indexToRemove+1)*sizeof(int));
  
      memmove(
              temp+indexToRemove,
              (*array)+(indexToRemove+1),
              (sizeOfArray - indexToRemove)*sizeof(int));
  
      free (*array);
      *array = temp;
      return 0;
  
  }
  
  int findDuplicate(int* array, int sizeOfArray){
      int i, j;
  
  
      for( j = 0 ; j &lt; sizeOfArray ; j++ ) {
          for(i = 0; i &lt; sizeOfArray; i++){
              if(array[i] == array[j] &amp;&amp; i != j){
                      return i;
              }
          }
      }
  
      return 0;
  }
  
  int main()
  {
     time_t t;
     srand((unsigned) time(&amp;t));
  
      int arraySize = 11;
      int* test = malloc(arraySize * sizeof(int*));
      int i, indexToRemove = 0;
  
     for( i = 0 ; i &lt; arraySize ; i++ ) {
        test[i] = ((rand() % (91 + 1 - 65)) + 65);
     }
  
      for( i = 0 ; i &lt; arraySize ; i++){
          printf("%d, ", test[i]);
      }
  
      printf("\n============================================\n");
  
      for (i = 0 ; i &lt; arraySize ; i++){
          indexToRemove = findDuplicate(test,arraySize);
  
          if ( indexToRemove != 0){
              remove_element(&amp;test, arraySize, indexToRemove);
              arraySize = arraySize - 1;  
          }   
      }
  
      for( i = 0 ; i &lt; arraySize ; i++){
          printf("%d, ", test[i]);
      }
  
      return 0;
  }
  </code></pre>