目前,我正在做w3resource中关于指针的练习.请帮我解释charPermu的参数以及为什么在主代码中给出(str,0,n-1)?
#include <stdio.h>
#include <string.h>
#define MAX 4
void changePos(char *ch1, char *ch2){
char tmp;
tmp = *ch1;
*ch1 = *ch2;
*ch2 = tmp;
}
void charPermu(char *cht, int stno, int endno){
int i;
if(stno == endno){
printf("%s ", cht);
} else{
for(i = stno; i<= endno; i++){
changePos((cht+stno), (cht+i));
charPermu(cht, stno+1, endno);
changePos((cht+stno), (cht+i));
}
}
}
int main(){
char str[MAX];
printf("\n\n Pointer : Generate permutations of a given string :\n");
printf("--------------------------------------------------------\n");
printf("Enter a string to permutate: ");
scanf("%[^\n]", str);
int n = strlen(str);
printf("The permutations of the string are: ");
charPermu(str, 0, n - 1);
printf("\n\n");
return 0;
}