The function that's probably missing for you is <combination.h>, which is not standard in the C library. I can include the code snippet I used for it, since I found it on an internet forum for such things.
I changed the test_all_zero code per your suggestion.
Code:
int test_all_zero(char* bitarray, int n){
int i;
int counter = 0;
for (i=0; i<n; i++){
if (!BITTEST(bitarray, i)){
counter++;
}
}
if (counter == n){
return (1);
}
else{
return (0);
}
}
And here's the <combination.h> header file:
Code:
/*
next_comb(int comb[], int k, int n)
Generates the next combination of n elements as k after comb
comb => the previous combination ( use (0, 1, 2, ..., k) for first)
k => the size of the subsets to generate
n => the size of the original set
Returns: 1 if a valid combination was found
0, otherwise
*/
int next_comb(int comb[], int k, int n) {
int i = k - 1;
++comb[i];
while ((i >= 0) && (comb[i] >= n - k + 1 + i)) {
--i;
++comb[i];
}
if (comb[0] > n - k) /* Combination (n-k, n-k+1, ..., n) reached */
return 0; /* No more combinations can be generated */
/* comb now looks like (..., x, n, n, n, ..., n).
Turn it into (..., x, x + 1, x + 2, ...) */
for (i = i + 1; i < k; ++i)
comb[i] = comb[i - 1] + 1;
return 1;
}
However, for DIM = 5 and LOWER = 3, I'm still getting an incorrect answer.
I can't figure out if my for/while loops are even engaging, since it seems that my program block is just getting skipped. Is that what's happening?