字符串循环右移n个单位
编写一个函数,作用是把一个char组成的字符串循环右移n个单位,比如源字符串是"helloworld",循环右移3个单位后,目标字符串是"rldhellowo"。
#include<iostream>
using namespace std;
#define MAX_LEN 20
void loopMove(char* strSrc, int n) {
int N = strlen(strSrc) - n;
char temp[MAX_LEN];
strcpy(temp, strSrc + N);
strcpy(temp + n, strSrc);
*(temp + strlen(strSrc)) = '\0';
strcpy(strSrc, temp);
}
int main()
{
char strSrc[20] = "helloworld";
loopMove(strSrc, 3);
cout << strSrc << endl;
return 0;
}