title: Remove Negative numbers from array in C
body: <p>I am trying to remove the negative numbers from array with the following code. Unfortunately, not getting the results. It just prints the first element over and over. Can someone please let me know where am I going wrong?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void removenegative(int a[],int *p, int *q);
  int main()
  {
      int a[] = {2, 3, -5, -7, 6, 9};
      int i;
      int *p, *q;
      p = a;
      q = a+6-1;
      removenegative(a, p,q);
      for(i=0;i&lt;6;i++)
          {
              printf("%2d", *p);
          }
      printf("\n");
  }
  void removenegative(int a[],int *p, int *q)
  {
      int *x;
      x= &amp;a[0];
      while (p&lt;=q)
          {
              if (*p&gt;=0)
                  {
                      *x = *p;
                      x++;
                  }
              p++;
          }
      for( ; x&lt;=q; x++)
          {
              *x = -1;
          }
  }
  </code></pre>