title: Fixing small error in output using arrays in C
body: <p>I am currently working on a project that when given a main function which calls another function confab(), outputs a serious of characters. The question refers to some made up race. They choose an integer nRows between 2 and half the length of the message, e.g. a message of length 11 would allow values of nRows in the range 2 to 5. The message is then written down the columns of a grid, one character in each grid cell, nRows in each column, until all message characters have been used. This may result in the last column being only partially filled. The message is then read out row-wise. </p>
  
  <p>For example the message "Don't wait until the last day before starting" with a nRows of 3 would return:</p>
  
  <pre><code>D'wtnlhltabo ai.ota t ea yersrnn iuit sd fettg
  </code></pre>
  
  <p>I have written code that does this fairly efficiently, however I have been provided with a test case that i cannot seem to work out.</p>
  
  <pre><code> char buffer[8] = {'*','*','*','*','*','*','*','*',};
  confab("ABCDEF.", 3, buffer);
  printf("%s\n", buffer);
  </code></pre>
  
  <p>Is this example, and the output it should give is:</p>
  
  <pre><code>AD.BECF
  </code></pre>
  
  <p>However my code returns:</p>
  
  <pre><code>AD.BECF*
  </code></pre>
  
  <p>Due to the extra * in the outText buffer not being replaced with a character. I have tried many things such as removing this extra *, or re initializing the outText to be the same length as the inText (within the code as the main case provided is not allowed to be edited), however nothing thus far has made a difference. </p>
  
  <p>I was wondering if there would be a quick edit I could apply to my code that would perform this change, as I cannot seem to find a way apart from editing the main input which is not allowed. </p>
  
  <p>My code is as follows:</p>
  
  <pre><code>/*
   * Confabulons.c
   * A program to encode for the Confabulons
   *
   * August 8th 2015
   */
  
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  //A simple function confab which given input text, and a number
  //of rows, returns a phrase in the Confabulons encoding scheme.
  
  void confab(const char inText[], int nRows, char outText[])
  {
      int count = 0;
      int i = 0;
      int z = 0;
      int len = strlen(inText);
  
      while (z &lt; nRows)
      {
          while (((int)inText[count] &gt; 0) &amp;&amp; (count &lt; len))
          {
              outText[i] = inText[count]; 
              i ++;
              count = count + nRows;
          }
          z ++;
          count = z;
      }
  }
  </code></pre>