title: Returning an array of structs without pointers in C
body: <p>I have been working my way through Kochan's "Programming in C" 3rd Edition on my own to get ready for grad school next year, and I am stuck for the first time. I am a chapter away from pointers, yet the exercise at the end of this most recent chapter on character strings has a problem that my own research seems to indicate can only be solved by using pointers.</p>
  
  <p>The question has to do with a data structure <code>entry</code>:</p>
  
  <pre><code>struct entry {
      char word[15];
      char definition[50];
  };
  </code></pre>
  
  <p>We create an array of entries:</p>
  
  <pre><code>struct entry dictionary[10] = 
  {{"aardvark", "a burrowing African mammal"},
   {"abyss", "a bottomless pit"},
   {"addle", "to become confused"},
   {"aerie", "a high nest"},
   {"ajar", "partially opened"},
   {"acumen", "mentally sharp; keen"},
   {"affix", "to append; attach"},
   {"agar", "a jelly made from seaweed"},
   {"ahoy", "a nautical call of greeting"},
   {"aigrette", "an ornamental cluster of feathers"}};
  </code></pre>
  
  <p>The prompt reads: "Write a function called <code>dictionary_sort</code> that sorts a dictionary, as defined [above], into alphabetical order."</p>
  
  <p>I know there are subtleties to structures and arrays in relation to functions and how functions can take them as arguments or give them back as returned values. The only way that seemed to make sense to me was returning a struct, or specifically an array of structs, but I do not think I applying it correctly here:</p>
  
  <pre><code>struct entry dictionary_sort(struct entry dictionary)
  </code></pre>
  
  <p>In total, my current version of the program is as follows:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  
  struct entry {
      char word[15];
      char definition[50];
  };
  
  // Function to compare two character strings
  
  int compare_strings(const char s1[], const char s2[])
  {
      int i = 0, answer; 
  
      while (s1[i] == s2[i] &amp;&amp; s1[i] != '\0' &amp;&amp; s2[i] != '\0')
          i++;
  
      if (s1[i] &lt; s2[i])
          answer = -1; // s1 &lt; s2
      else if (s1[i] == s2[i])
          answer = 0; // s1 == s2
      else
          answer = 1; // s1 &gt; s2
  
      return answer;
  }
  
  // Function to sort a dictionary structure
  
  struct entry dictionary_sort(struct entry dictionary[])
  {
      int dictionary_length = sizeof(dictionary) / sizeof(dictionary[0]);
      int i, j, minimum;
      struct entry temp;
  
      for (i = 0; i &lt; dictionary_length; i++) {
          minimum = i;
          for (j = i + 1; j &lt; dictionary_length; j++) {
              if (compare_strings(dictionary[j].word, 
                                  dictionary[minimum].definition) == -1)
                  minimum = j;
          }
          temp = dictionary[minimum];
          dictionary[minimum] = dictionary[i];
          dictionary[i] = dictionary[minimum];
      }
  
      return dictionary;
  }
  
  int main(void)
  {
      struct entry dictionary[10] =
      {{"aardvark", "a burrowing African mammal"},
       {"abyss", "a bottomless pit"},
       {"addle", "to become confused"},
       {"aerie", "a high nest"},
       {"ajar", "partially opened"},
       {"acumen", "mentally sharp; keen"},
       {"affix", "to append; attach"},
       {"agar", "a jelly made from seaweed"},
       {"ahoy", "a nautical call of greeting"},
       {"aigrette", "an ornamental cluster of feathers"}};
      int i, dictionary_length = sizeof(dictionary) / sizeof(dictionary[0]);
  
      dictionary = dictionary_sort(dictionary);
  
      for (i = 0; i &lt; dictionary_length; i++)
          printf("%s - %s.\n", dictionary[i].word, dictionary[i].definition);
  
      return 0;
  }
  </code></pre>
  
  <p>The string comparison function behaves as expected since it is only returning an integer. I am really at a loss as to how to have the desired functionality without knowledge of pointers. There are enough examples <em>with</em> pointers to look up, but I am curious what fundamental principle I am missing here because I feel as though everything else in the book has come very naturally to me.</p>
  
  <p>Thank you in advance!</p>