qsort is not really sorting
In your program there is this line of code:

  return redA-&gt;rssi &gt; redB-&gt;rssi ? 1 : (redB-&gt;rssi &lt; redA-&gt;rssi ? -1 : 0);


Which appears to return a 1 if A is greater then B other wise it will return a 0.  This code can not tell the difference between A &lt; B and A == B.  Consider altering this line of code to allow returning 1 for A > B, 0 for A == B and -1 for A &lt; B:

  return redA-&gt;rssi &gt; redB-&gt;rssi ? 1 : (redA-&gt;rssi &lt; redB-&gt;rssi ? -1 : 0);