I have been trying to print all the combination of a string using recursive call. I have studied a code given below . It prints the combination but now i have to store the strings in an array .
And i don't get it how do i do that ?
Input ABC
Output
ABC
ACB
BAC
BCA
CAB
CBA
All in an array
void permute(char *a, int i, int n)
{
int k=0;
char *b[100];
int j;
if (i == n)
{
// *b[k]=a;
printf("%s\n", a);
i++;
}
else
{
for (j = i; j <= n; j++)
{
swap((a+i), (a+j));
permute(a, i+1, n);
swap((a+i), (a+j)); //backtrack
}
}
}