title: Backtracking algorithm to generate all combinations
body: <p>I have a little problem with this.I want to generate every possible combination.The numbers located in 1D array and it is read from a file. Now I don't know the problem: I know that every combination which will be printed to monitor is in ascending order. The probelm is that if it finishes with smallest number it doesn't ascends to the next number.</p>
  
  <p>Example: The 1D array file  with 1,2,3,4,5 and n = 5 and p = 3;
  Possible combinations:</p>
  
  <p>1 2 3,
  1 2 4,
  1 2 5,
  1 3 4,
  1 3 5,
  1 4 5,
  2 3 4,
  2 3 5,
  etc...</p>
  
  <p>Here is what I done so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void print(int*,int);
  void combination(int*,int,int,int);
  int main()
  {
      FILE *fin = fopen("bemenet.txt","r");
      if(!fin){printf("Error opening file @!!!");return 0;}
      int *a,i,n,p = 3;
      fscanf(fin,"%i ",&amp;n);
      a = (int*)malloc(n*sizeof(int));
      for(i = 0; i &lt; n; ++i){
          fscanf(fin,"%i ",&amp;a[i]);
      }
      combination(a,n,p,0);
  
      return 0;
  }
  
  void combination(int *a,int n,int p,int k)
  {
      int i;
      if(k == p){
          print(a,k);
      }
      else{
          for(a[k + 1] = a[k] + 1 ; a[k+1] &lt; n; ++a[k+1]){
              combination(a,n,p,k+1);
          }
      }
  }
  void print(int *a,int k)
  {
      int i;
      for(i = 0; i &lt; k; ++i){
          printf("%i ",a[i]);
      }
      printf("\n");
  }
  </code></pre>