#include <QCoreApplication>
//移动后面n个字节到前面,前面字符串后移。比如"123456", n = 3,
//运行结果456123
char* loopmove(char* str, int n){
if(str == NULL) return NULL;
char* head = str;
char* head2 = str;
char* buf = (char *)malloc(n);
int strLen = strlen(str);
//拷贝后面n个字符到buf
for(int i = 0; i < n; i++ ){
buf[i] = str[strLen - n + i];
}
//str 前面字节移动到后面
for(int j = strLen - 1; j >= n; j--){
head[j] = head[j - n];
}
memcpy(str, buf, n);
free(buf);
return head2;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
char str[] = "123456";
char* P = loopmove(str, 3);
puts(P);
return a.exec();
}