I am trying to make a program which prints all the possible permutations of the string "A?B?AB?" via replacing question marks with A or B. I can't understand why my code works the way it does and need help improving it.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* rec(char s[8]){
    int i=0;
    for(;i<strlen(s);i++){
    if(s[i]=='?'){
        s[i]='A';
        rec(s);
        s[i]='B';
        rec(s);
        s[i]='?';
    }
    }
    for(int k=0;k<strlen(s);k++){
        if(s[k]=='?')
            i=-1;
    }
        if(i!=-1)
            printf("%s\n",s);
    return s;
}
int main(){
    char s[8]="A?B?AB?";
    rec(s);
}
 
     
     
    