我想了解为什么某些字符会在原始字符串中连接后消失。看,c = *sibl
接收 的第一个字符*sibl
,
*sibl = *inout
接收 的内容,*inout
但存储的字符c
不在 中*inout
。而且,*inout = c
不会改变 的内容*inout
,它c
会连接到 的内容*inout
。我不明白为什么会这样!
我的代码:
void Cripto (char *inout, int i) {
char *sibl, c;
while (*inout) {
sibl = inout+1;
if (!sibl)
break;
if (*inout >= 'A' && *inout <= 'Z'){
*inout += i;
}
c = *sibl;
printf("val c %c\n",c);
printf("val inout after c %s\n",inout);
printf("val sibl after c %s\n",sibl);
*sibl = *inout;
printf("val sibl after att %s\n",sibl);
*inout = c;
printf("val inout after att %s\n",inout);
inout = sibl+1;
}
}
int main() {
char str[30];
int i;
scanf("%s %d", str, &i);
Cripto(str, i);
printf("%s\n", str);
return 0;
}
"teste" 3 的结果:
val c: e
val inout after c: teste
val sibl after c: este
val sibl after att: tste
val inout after att: etste
val c: t
val inout after c: ste
val sibl after c: te
val sibl after att: se
val inout after att: tse
val c:
val inout after c: e
val sibl after c:
val sibl after att: e
val inout after att: