代码实现
int rightShiftStr(char * str, int n){
if(NULL == str){
printf("addBigInt param error\n");
return PARAM_ERR;
}
int len = strlen(str);
if(n > len){
printf("addBigInt param error2\n");
return PARAM_ERR;
}
char * p = NULL;
char * t = str + len - 1;
char buf[100] = {'\0'};
int k = 0;
p = t - n + 1;
for(k = 0; k < n; k++){
buf[k] = *p;
p++;
}
p = str + n;
memcpy(p, str, len - n);
p = str;
for(k = 0; k < n; k++){
*p = buf[k];
p++;
}
return SUCCESS;
}
void testrightShiftStr(void){
char str[100] = "123456789";
printf("\n************ testrightShiftStr ************ \n");
rightShiftStr(str, 6);
printf("right shift 6 is : %s\n", str);
return;
}
代码编译
gcc main.c str.c -g -o a.exe
代码输出
************ testrightShiftStr ************
right shift 6 is : 456789123