Using the C language I have to write a program that computes all possible combinations of a given string.
Example Input:
ABC
Example Output:
A,B,C,AB,AC,BC,ABC.
I wrote this code and it works for my example input, but currently it works only for Strings which are exactly 3 characters long. I want to modify my program so that it can accept a string of N characters lenght and still give the correct output.
This is my code so far:
int position1 = 0;
int position2 = 0;
char conjuntoQ[100]="\0";
size_t len;
while (m1.q[position1] != NULL) {
position2 = position1;
position2++;
while (m1.q[position2] != NULL) {
len = strlen(conjuntoQ);
conjuntoQ[len] = m1.q[position];
len = strlen(conjuntoQ);
conjuntoQ[len] = m1.q[position2];
len = strlen(conjuntoQ);
conjuntoQ[len] = ',';
position2++;
}
position++;
}