title: C - copy array without duplicates
body: <p>for learning purposes I'm trying to copy an array to a new empty array -skipping the duplicates, my logic is that a nested for loop  will check for duplicates and when it finds one it will skip it's parent's counter.</p>
  
  <p>however the resulting array is always the original array's last number, repeated N times.</p>
  
  <p>EDIT: The program should work with unsorted arrays and when the duplicates aren't consecutive.</p>
  
  <p>please help</p>
  
  <p>full code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main() {
  int array[10]={1,2,3,3,5,6,7,8,9,10};
  int arrayB[10];
  int i=0;
  int j=0;
  int lengthB=10;
  
  // routine for copying array without duplicates
  for (i=0;i&lt;10;i++) {
      for(j=0;j&lt;=i;j++){
  
               if (array[i]==arrayB[j]) {
               lengthB--;
               i++;                  
          }
               else{
               arrayB[j]=array[i];
               }
          }
  
  }        
  //display copied array:
  printf("\n");
  for(i=0;i&lt;lengthB;i++)
  printf("%d\t",arrayB[i]);
  
  return 0;
  }
  </code></pre>