title: Most efficient way to print alpha ranges?
body: <p>I would like to make a simple program: it gets 2 strings as input, and outputs everything between them. For example, for input 'a' , 'b' , output is:</p>
  
  <pre><code>a b
  </code></pre>
  
  <p>for input 'a' , 'zz' , output is:</p>
  
  <pre><code>a b c ... x y z aa ab ac ... ax ay az ba bb bc ... bx by bz ... za zb zc ... zx zy zz
  </code></pre>
  
  <p>What is the most efficient way to do it?</p>
  
  <p>---- EDIT ----</p>
  
  <p>Here are my implementations, first using recursion:</p>
  
  <pre><code>void rec_print(int current)
  {
      if(current == max_len)
      {
          for(char c='a'; c&lt;= 'z'; ++c)
          {
              global[current] = c;
              printf("%s\n", global);
  
          }
      }
      else
      {
          for(char c='a'; c&lt;= 'z'; ++c)
          {
              global[current] = c;
              rec_print(current+1);
          }
      }
  }
  </code></pre>
  
  <p>And then using loops:</p>
  
  <pre><code>void loop_print()
  {
      char *buffer;
      int i;
  
      for( int len=1; len&lt;= 5; len++)
      {
          buffer = calloc(len+1, sizeof(char));
          memset(buffer, 'a', len);
  
          printf("buffer = %s\n", buffer);
  
          system("pause");
  
          do
          {
              i=len-1;
  
              for(char c='a'; c&lt;='z'; ++c)
              {
                  buffer[len-1] = c;
                  printf("%s\n", buffer);
              }
  
              while(i &gt; -1 &amp;&amp; buffer[i] == 'z')
              {
                  buffer[i] = 'a';
                  i--;
              }
  
              buffer[i]++;
  
  
          }
          while (i != -1);
      }
  
  
  }
  </code></pre>
  
  <p>---- EDIT 2 ----</p>
  
  <p>answered my question</p>