关于C语言程序,求大神帮忙解答
轮换
串“abcd”每个字符都向右移位,最右的移动到第一个字符的位置,就变为“dabc”。这称为对串进行位移=1的轮换。同理,“abcd”变为:“cdab”则称为位移=2的轮换。
代码如下:
1 #include <string.h>
2 #include <stdlib.h>
3 void shift(char* s, int n)
4 {
5 char* p;
6 char* q;
7 int len = strlen(s);
8 char* s2;
9 if(len==0) return;
10 if(n<=0 || n>=len) return;
11 s2= (char*)malloc(sizeof(char)*(len+1));
12 p = s;
13 q = s2 + n % len;
14 while(*p)
15 {
16 *q++ = *p++;
17 if(q-s2>=len)
18 {
19 *q = '\0';
20 q = s2;
21 }
22 }
23 strcpy(s,s2);
24 free(s2);
25 }
26 void main()
27 {
28 char str[10] = "zhanghe";
29 shift(str,2);
30 printf("%s\n",str);
31 }
请问11行为什么是len+1?
12行13行又是什么意思,p、q代表什么?
17行是什么意思?