我的代码如下
#include <stdio.h>
#include <string.h>
void permutation(char str[], int len, int cur)
{
if (cur == len - 1) {
printf("%s
", str);
}
char tmp;
for (int i = cur; i < len; i++) {
tmp = str[cur];
str[cur] = str[i];
str[i] = tmp;
permutation(str, len, cur++);
tmp = str[cur];
str[cur] = str[i];
str[i] = tmp;
}
}
int main() {
char* str = "abc";
int len = strlen(str);
permutation(str, len, 0);
}
在str[cur] = str[i]
这里报EXC_BAD_ACCESS ,但是我又不知道问题出在哪。还请各位大佬帮忙看看。
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…