title: Sorting words in a character array
body: <p>For the given array, I need to write a function to sort words alphabetically:</p>
  
  <pre><code>char strings [][10] = {
      "hello",
      "world",
      "computers",
      "are",
      "awesome"
  };
  </code></pre>
  
  <p>I've tried to write the function <code>sortWords</code> by using insertion sort, but I think my swap function isn't working:</p>
  
  <pre><code>void swap(char *e1, char *e2) {
      int tmp = *e1;
      *e1 = *e2;
      *e2 = tmp;
  }
  
  void sortWords( char (* words2Darray)[10], unsigned short length ) {
      unsigned int i, curPos;
      char curChars[10];
  
      for(i = 1; i &lt; length; i++) {
          // Copy the current word into curChars
          strncpy_s(curChars, words2Darray[i], 10);
          curPos = i;
  
          // Compare and move the word to the correct position
          while(curPos &gt; 0 &amp;&amp; strcmp(curChars, words2Darray[i-1]) &gt; 0) {
              swap(words2Darray[curPos], words2Darray[curPos-1]);
              curPos--;
          }
      }
  }
  </code></pre>
  
  <p>I've attempted debugging my code using the Local Windows Debugger and found that <code>curChars</code> is being copied properly.</p>
  
  <p>Can someone please <em>explain</em> to me what I am doing wrong and how I should go about solving this problem? I'm not allowed to use <code>std::string</code> in this problem. <strong>No full solutions please!</strong></p>