title: Python's itertools.product in C
body: <p>There is a function in Python which runs this way:</p>
  
  <pre><code>itertools.product("abc", repeat = 2)
  </code></pre>
  
  <p>returns the following:</p>
  
  <pre><code>("a", "a")
  ("a", "b")
  ("a", "c")
  ("b", "a")
  ("b", "b")
  ("b", "c")
  ("c", "a")
  ("c", "b")
  ("c", "c")
  </code></pre>
  
  <p>Changing the repeat variable will change how many items come back in a tuple.
  How can this be written in C to return an array of arrays of chars? (an array of strings)</p>
  
  <p>UPDATE: I now have this function I wrote:</p>
  
  <pre><code>void cartesian(char *a, int al, char *b, int bl){
      int i, j;
      char c[al * bl][2];
      for(i = 0; i &lt; al; i++){
          for(j = 0; j &lt; bl; j++){
              c[(i * bl) + j][0] = *(a + i);
              c[(i * bl) + j][1] = *(b + j);
              printf("%c%c\n", *(a + i), *(b + j));
          }
      }
  }
  
  int main(){
      char a[] = "abc";
      char b[] = "ab";
      cartesian(a, strlen(a), b, strlen(b));
      return 0;
  }
  </code></pre>
  
  <p>How can I change this function so it can take in an array of of arrays of char and make the cartesian product? The arrays could contain any number of chars and there could be any number of arrays</p>
  
  <p>The function should look like:</p>
  
  <pre><code>void cartesian(char *a, int l){
      /*Do cartesian*/
  }
  </code></pre>
  
  <p>Example array:</p>
  
  <pre><code>[
      ['a', 'b', 'c', '\0'],
      ['a', 'b', 'c', '\0'],
      ['a', 'b', 'c', '\0']
  ]
  </code></pre>
  
  <p>(nulls included to work out length of arrays)
  should produce</p>
  
  <pre><code>[
      ['a', 'a', 'a'],
      ['a', 'a', 'b'],
      ['a', 'a', 'c'],
      ['a', 'b', 'a'],
      ['a', 'b', 'b'],
      ['a', 'b', 'c'],
      ['a', 'c', 'a'],
      ['a', 'c', 'b'],
      ['a', 'c', 'c'],
      ['b', 'a', 'a'],
      ['b', 'a', 'b'],
      ['b', 'a', 'c'],
      ['b', 'b', 'a'],
      ['b', 'b', 'b'],
      ['b', 'b', 'c'],
      ['b', 'c', 'a'],
      ['b', 'c', 'b'],
      ['b', 'c', 'c'],
      ['c', 'a', 'a'],
      ['c', 'a', 'b'],
      ['c', 'a', 'c'],
      ['c', 'b', 'a'],
      ['c', 'b', 'b'],
      ['c', 'b', 'c'],
      ['c', 'c', 'a'],
      ['c', 'c', 'b'],
      ['c', 'c', 'c'],
  ]
  </code></pre>