指针问题
void shift(char* s, int n){
char* p;
char* q;
int len = strlen(s);
if(len==0) return;
if(n<=0 || n>=len) return;
char* s2 = (char*)malloc(len+1); // 填空1
p = s;
q = s2 + n % len;
while(*p)
{
*q++ = *p++;
if(q-s2>=len)
{
*q = 0; // 填空2
q = s2;
}
}
strcpy(s,s2);
free(s2);
}
int main(int argc, char* argv[])
{
char x[] = "abcdefg";
shift(x,6);
printf("%s\n", x);
return 0;
}
q = s2 + n % len;
是什么意思