I am trying to make a program that, with a given word, can calculate and print every letter combination. To be more specific, I am asked to use a recursive function and what I should get is something like this:
Given word: HOME
EHOM
EMOH
MEHO
The approach I am taking in to swap the content #x with #x+1 like this
string[0]->string[1]
string[0]->string[2]
This is what I came up with
void anagram(char * s, int len, int y)
{
char temp; //used to store the content to swap betwen the two
if (len < 0) //when the total lenght of the array gets to 0 it means that every single swap has been made
return;
temp = s[len]; //swapping
s[len] = s[y];
s[y] = temp;
puts(s); //prints the string
if (y == 0)
return anagram(s, len-1, y - 1);
return anagram(s, len, y - 1);
}
What I get is just a huge mess and a Break Point from VS (if not a crash).
Can somebody help me please?