title: Need help creating a parallel array in C
body: <p>Just a disclaimer: I am a complete noob when it comes to C programming and this might be embarrassingly easy but I can't think it out myself and haven't found anything otherwise helpful. Anyways, this program below is supposed to put names (last, first) and ages into arrays and then alphabetize them. The problem I have is creating a sort of parallel array to match ages with their respective names after sorting them alphabetically. Does anyone have any suggestions? I was thinking of somehow tying the age array into my defined functions, but I still can't wrap my head around that either. Thanks in advance!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #define NAME_LENGTH 50
  #define MAX_NAMES 50
  
  int alpha_first(char *list[], int min_sub, int max_sub);
  void select_sort_str(char *list[], int n);
  
  int
  main(void)
  {
      int i = 0;
      int numpeople;
      char names[MAX_NAMES][NAME_LENGTH] = { 0 };
      char ages[MAX_NAMES][NAME_LENGTH] = { 0 };
      char skip_line;
      char *alpha[MAX_NAMES] = { 0 };
  
      printf("Enter number of people &lt;0..50&gt;\n&gt; ");
      scanf("%d", &amp;numpeople);
  
      do
      {
          scanf("%c", &amp;skip_line);
      }
      while (skip_line != '\n');
  
  
      for(i = 0; i &lt; numpeople; ++i)
      {
          printf("Enter name %d (lastname, firstname) ", i+1);
          gets(names[i]);
  
          printf("Enter age %d: ", i+1);
          gets(ages[i]);
  
      }
  
      for(i = 0; i &lt; numpeople; ++i)
      {
          alpha[i] = names[i];
          select_sort_str(alpha, numpeople);
      }
  
      printf("\n\n%-30s\n\n", "Original List");
      for  (i = 0;  i &lt; numpeople;  ++i)
          printf("%-30s\n", names[i]);
      printf("\n\n%-30s\n\n", "Alphabetical Order");
      for  (i = 0;  i &lt; numpeople;  ++i)
          printf("%-30s\n", alpha[i]);
  
      return 0;
  
  }
  
  int
  alpha_first(char *list[],
              int min_sub, int max_sub)
  {
      int first, i;
  
      first = min_sub;
      for (i = min_sub + 1; i &lt;= max_sub; ++i)
              if (strcmp(list[i], list[first]) &lt; 0)
                  first = i;
      return (first);
  }
  
  
  void
  select_sort_str(char *list[], int n)
  {
      int fill, index_of_min;
      char *temp;
  
      for (fill=0; fill&lt;n-1; ++fill)
      {
          index_of_min = alpha_first(list, fill, n - 1);
  
          if (index_of_min != fill)
          {
              temp = list[index_of_min];
              list[index_of_min] = list[fill];
              list[fill] = temp;
          }
      }
  }
  </code></pre>