title: How to pass a designator of which member of a structure to a function in C
body: <p>I have a lot of records formed by 4 parameters each one (id, field1, field2, field3). Records are contained in a pointer called <code>records</code>. My goal is to create an InsertionSort function in order to sort these records. The sorting will be done for every parameter of the record (through multiple calling). The trouble is that the function must be general.
  What can I write in parameters of InsertionSort function so that the pointer works?</p>
  <p><strong>main.c</strong></p>
  <pre><code>struct fields{
      int id;
      char field1[20];
      int field2;
      float field3;
  };
  
  int main() {
  struct fields *records = malloc(100000 * sizeof *records);
  
  /* Here , I fill *records with values */
  
  InsertionSort(records,field1,100000);     // I order by parameter &quot;field1&quot;
  InsertionSort(records,id,100000);      // I order by parameter &quot;id&quot;
  InsertionSort(records,field2,100000);     // I order by parameter &quot;field2&quot;
  }
  </code></pre>
  <p><strong>InsertionSort function</strong></p>
  <pre><code>void InsertionSort(fields *records, char parameter ,int sizeofrecords) {
          int i, j;
          void* temp;
          for (i = 1; i &lt; size; i++) {
              temp = records[i].parameter;   //this command doesn't work (records[i])
              j = i - 1;
              while (j &gt;= 0 &amp;&amp; records[j].parameter&gt; temp) {
                  records[j + 1].parameter= records[j].parameter;
                  j--;
              }
              records[j + 1].parameter= temp;
          }
      }
  </code></pre>