Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define CHUNK 1024
void combinations(char nums[],char candidate[],int current_len,int n3,int len) {
if(current_len == len) {
printf("%s\n", candidate);
return;
}
else {
int i;
for(i=0; i < n3; i++) {
candidate[current_len] = nums[i];
combinations(nums,candidate,current_len+1,n3,len);
}
}
}
int main() {
// ---- Reading the data from ASCII text ----
int match[32];
int length;
char buf[CHUNK];
FILE *file;
size_t nread;
file = fopen("data.txt", "r");
if(file) {
while((nread = fread(buf,1,sizeof buf, file)) > 0) {
fwrite(buf,1,nread,stdout);
match[32] = nread;
length = nread-1;
printf("\n%d\n", length);
}
fclose(file);
}
// -------------------------------------------
char lc_letters[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v'};
char up_letters[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V'};
char nums[] = {'0','1','2','3','4','5','6','7','8','9'};
char candidate[32];
char output[32];
int n = sizeof(lc_letters)/sizeof(lc_letters[0]);
int n2 = sizeof(up_letters)/sizeof(up_letters[0]);
int n3 = sizeof(nums)/sizeof(nums[0]);
int count = length;
char arr[10] = "";
char new_str[21];
combinations(nums,arr,0,n3,count);
}
Now let me explain this: what I'm trying to do is to read the text data from a file (OK here, it works) and then to do all the possible combinations of words or numbers. In this case I just created the combinations of the numbers in order to see if it works with one case and then go on like that with the others, but it's not like that. I can create my combinations with the void function called "combination" but here comes the problem: