title: Sorting an array of pointers to a struct on the basis of a struct member - best possible option?
body: <p>I have the following struct: </p>
  
  <pre><code>typedef struct details clientDetails;
  struct details 
  {
      int socket;  
      char* port;
      char* IP;
      char* hostName;
      int msgSentCount;
      int msgRecvCount;
      char* status;
      char* bufferMsg;
      char* blockedUser[4];
      int blockedCount;   
  };
  </code></pre>
  
  <p>And I have the following array of pointers to the struct:</p>
  
  <p><code>clientDetails* allClients[4];</code></p>
  
  <p>What would be the best possible way to keep the array sorted by the <code>port</code> number of the struct? </p>
  
  <p>The implementation required would be as follows:</p>
  
  <p><code>sortByPort(allClients)</code> -> passes a reference to the array and sorts it so that if I print the values of <code>allClients</code> after this function call, I will have it sorted by the <code>port</code> number.</p>