title: Why are negative numbers greater than positive numbers?
body: <p>I made my bubble sort program generic. I went on testing it and it was working well until I placed a negative number in the array, and I was surprised that it was pushed to the end, making it bigger than positive numbers.  </p>
  
  <p>Obviously <code>memcmp</code> is the reason, so why does <code>memcmp()</code> regard negative numbers greater than positive numbers?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  void bubblesortA(void *_Buf, size_t bufSize, size_t bytes);
  
  int main(void)
  {
      size_t n, bufsize = 5;
      int buf[5] = { 5, 1, 2, -1, 10 };
      bubblesortA(buf, 5, sizeof(int));
  
      for (n = 0; n &lt; bufsize; n++)
      {
          printf("%d ", buf[n]);
      }
      putchar('\n');
  
      char str[] = "bzqacd";
      size_t len = strlen(str);
      bubblesortA(str, len, sizeof(char));
  
      for (n = 0; n &lt; len; n++)
      {
          printf("%c ", str[n]);
      }
      putchar('\n');
      return 0;
  }
  
  void bubblesortA(void *buf, size_t bufSize, size_t bytes)
  {
      size_t x, y;
      char *ptr = (char*)buf;
      void *tmp = malloc(bytes);
      for (x = 0; x &lt; bufSize; x++)
      {
          ptr = (char *)buf;
          for (y = 0; y &lt; (bufSize - x - 1); y++)
          {
              if (memcmp(ptr, ptr + bytes, bytes) &gt; 0)
              {
                  memcpy(tmp, ptr, bytes);
                  memcpy(ptr, ptr + bytes, bytes);
                  memcpy(ptr + bytes, tmp, bytes);
              }
              ptr += bytes;
          }
      }
      free(tmp);
  }
  </code></pre>
  
  <p><strong>Edit</strong>:<br>
  So, How do I modify the program to make it compare correctly?</p>