title: Deleting Elements from an Array based on their Position every 3 Elements
body: <p>I created an array called <code>elements_n</code> which has the elements <code>0</code> to <code>N-1</code> where <code>N</code> is 2. The below numbers are the elements of the array called <code>elements_n</code>:</p>
  
  <pre><code>0 1 
  </code></pre>
  
  <p>I have another array called <code>Arr</code> which has the following elements:</p>
  
  <pre><code>0 1 3 1 2 4 
  </code></pre>
  
  <p>If any of the first 3 elements of the array <code>Arr</code> are equal to the first element of <code>elements_n</code> which is <code>0</code>, I would like to delete that element from the array called <code>Arr</code>. I then repeat the same process for the next 3 elements of the array <code>Arr</code>. So to explain myself better, I will use the following example:</p>
  
  <p>Compare the first 3 elements of array <code>Arr</code> which are 0, 1, 3  to the first element of <code>elements_n</code> which is 0. Since <code>Arr[0] == elements_n[0]</code>. I delete <code>Arr[0]</code> from the array <code>Arr</code>. </p>
  
  <p>Compare the next 3 elements of array <code>Arr</code> which are 1, 2, 4 to the second element of <code>elements_n</code> which is 1. Since <code>Arr[3] == elements_n[1]</code>. I delete <code>Arr[3]</code> from the array <code>Arr</code>. So the elements that should be left in the array <code>Arr</code> are:</p>
  
  <pre><code>1 3 2 4
  </code></pre>
  
  <p>When I implemented it myself in C programming with the code found below the end result is coming:</p>
  
  <pre><code> 1       3       3       2       2       4
  </code></pre>
  
  <p>Rather than:</p>
  
  <pre><code>  1       3       2       4
  </code></pre>
  
  <p>This is the code I implemented:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #define N 2 
  
  int main() {    
      unsigned *elements_n = malloc(N * sizeof(unsigned));
  
      for (int i = 0; i &lt; N; i++) {
          elements_n[i] = i; //Created an array which has the elements 0 to N-1
      }
      printf("\n");
  
      unsigned Arr[6] = { 0, 1, 3, 1, 2, 4 };
      unsigned position_indices[2] = { 3, 3 };  //Moving every 3 elements in the Arr array. 
  
      int count = 0; 
      int index = 0;
      unsigned *ptr_Arr = &amp;Arr[0];
  
      do {
          for (int i = 0; i &lt; position_indices[count]; i++) {
              if (ptr_Arr[i] == elements_n[count]) {
                  index = i + 1; //Index of the Arr element that has the same value as the element in the array elements_n 
  
                  for (int j = index - 1; j &lt; position_indices[count] - 1; j++) {
                      ptr_Arr[j] = ptr_Arr[j + 1];
                  }
              }
          }
          printf("\n");
          ptr_Arr += position_indices[count] - 1; 
          count++;
      } while (count &lt; 2);
  
      for (int i = 0; i &lt; 6; i++) {
          printf("%d\t", Arr[i]);
      }
      printf("\n");
  
      free(elements_n);
  
      return 0;
  }
  </code></pre>