轮换字符串
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);/*char* s2=(char*)malloc()*/
p=s;
q=s2+n%len;
while(*p)
{
*q++=*p++;
if(q-s2>=len)
{
*q='\0';/* *q= */
q=s2;
}
}
strcpy(s,s2);
free(s2);
}
我注释的那两个地方帮改下,在说下原因,最好详细些,多谢