写一函数,完成字串循环右移
如"abcdefghi",循环右移2位后成为"hiabcdefg"
void tranStr( char *pStr, int n );
#include "stdafx.h" #include<iostream> #include<string> #include<cstring>
using namespace std; void tranStr(char *pStr,int num){ char *back=new char[num+1]; strcpy(back,pStr+strlen(pStr)-num); char *front = new char[strlen(pStr)-num]; strncpy(front,pStr,strlen(pStr)-num); strcat(back,front); pStr=back; } int _tmain(int argc, _TCHAR* argv[]) { char *s1="abcdefghijk"; tranStr(s1,2); cout<<s1<<endl; }
|
阅读(784) | 评论(0) | 转发(0) |