title: Permutations with Repetitions in C; Valgrind Errors
body: <p>I'm trying to write a program where essentially I am trying to figure out the combination of a combination lock. I take in two inputs from the user, the number of dials to be turned (which I've called max indices) and the highest number each dial can go to (which I've called max number). Taking these two inputs, I'm simply trying to brute force my way into the lock. </p>
  
  <p>So to solve this problem, I tried to take a recursive approach as seen by the function openHelper. Each time a complete combination is created it is tested by a separate function testCombo, and it outputs one of three values. It outputs 1 if the combination worked, -2 if the combination failed and you cannot try anymore, and -1 if the combination failed but you can keep guessing.</p>
  
  <p>However, when testing this using valgrind, I get this error repeatedly: Process terminating with default action of signal 11 (SIGSEGV). </p>
  
  <p>Is there something I'm doing wrong with creating the arrays or is there just something wrong with the way I've designed the program?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int openHelper(int *input, int *output, int current_index, int max_index,
          int max_number);
  
  int open(max_value, max_indices)
  {
      int numbers[max_value];
      int test[max_indices];
  
      int i; 
      int x;
      /* Create array of all possible numbers */
      for(i = 0; i &lt; max_value; i++){
          numbers[i] = i;
      }
      x = openHelper(numbers, test, 0, (max_indices - 1), max_value);
      return x;
  }
  
  int openHelper(int *input, int *output, int current_index, int max_index,
          int max_number)
  {
      int i;
      int x;
      for(i = 0; i &lt; max_number; i++){
          output[current_index] = input[i];
  
          if(current_index == max_index){
              x = testCombo(output);
              if(x != -1){
                  return x;
              }
          }
          else{
              openHelper(input, output, (current_index + 1), max_index,
                      max_number);
          }
      }
  }
  </code></pre>
  
  <p>Test combo works by having a counter within the program. So if the counter is set to 10 after 10 tries it will return -2. Each time a combination is tried the counter gets decremented.</p>