If you're trying to iterate all combinations of k=5 on n=36, this is how you loop through them.
int k = 5;
int n = 36;
int count = 0;
for (int i1=1; i1 <= n-k+1; i1++)
for (int i2=i1+1; i2 <= n-k+2; i2++)
for (int i3=i2+1; i3 <= n-k+3; i3++)
for (int i4=i3+1; i4 <= n-k+4; i4++)
for (int i5=i4+1; i5 <= n-k+5; i5++)
printf("%d: %d %d %d %d %d\n", ++count, i1,i2,i3,i4,i5);
This is the simplest way to generate them, using a manual for-loop for each value in k. You can write a script to generate these for-loops for any required values of k.
Dynamic Solutions
This can be implemented dynamically with recursion, shown in 'recurse_combinations.c'.
This can also be implemented dynamically using next-state heuristics, shown in 'next_combination.c'.
Speed
The number of combinations are astronomical for all but the smallest values of k. So the time to complete is going to be very long for sufficiently sized values of k, regardless of the chosen generator solution. (I wasn't able to determine which performed better as they responded differently to different optimization flags specific to the gcc compiler.)