title: C- Decision function to swap strings or numbers inside array of structs
body: <pre><code>typedef struct Workers
  {
  char id[10];
  char *fName;
  char *lName;
  int  yob;
  int monthlyHours;
  int salary;
  
  
  
  }workers;
  </code></pre>
  
  <p>so i have a struct that is filled with workers details.
  in the main menu the user enters an option either to :
  1.sort by id
  2.sort by first name
  3.sort by monthly hours
  i need to create a decision function which is a pointer function that will sort the struct by the selected option  either by string or by integer.</p>
  
  <p>i wrote a bubble sort function and a swap function but don't have the slightest clue how to make a decision function that can handle all type of sorts </p>
  
  <p>current state of swap function</p>
  
  <pre><code>int me_compare(workers *me1, workers *me2) {
  int surnameResult;
  
  surnameResult = strcmp(me1-&gt;fName, me2-&gt;fName);
  
  return surnameResult;
  }
  </code></pre>
  
  <p>current state of sort function</p>
  
  <pre><code>void sortStruct(workers newWorkers[N], int numOfSort)
  {
  workers tmp;
  workers tmp2;
  int i = 0;
  int j = 0;
  
  int result;
  int swapped;
  for ( i = 0;( i &lt; N-1); i++)
  {
      swapped = 0;
      for (j = 0; j &lt; N-i - 1; j++)
      {
          tmp = newWorkers[j];
          tmp2 = newWorkers[j + 1];
          result = me_compare(&amp;tmp, &amp;tmp2);
          if (result == 1)
          {
              newWorkers[j] = tmp2;
              newWorkers[j + 1] = tmp;
              swapped = 1;
          }
      }
      if (swapped == 0)
          break;
  
  }
  
  }
  </code></pre>
  
  <p>any tips for me how to handle this ? </p>