例如:输入abcdefgh,循环右移34位,输出ghabcdef
- #include <stdio.h>
- #include <string.h>
- #define MAX_SIZE 1024
- char *move(char *input,int n)
- {
- if(input == NULL)
- {
- return NULL;
- }
- int i;
- int len = strlen(input);
- char *p = input;
- static char str[MAX_SIZE];
- p = p + len - (n % len);
- for(i = 0; i < (n % len); i++)
- {
- str[i] = *p;
- p++;
- }
- strcat(str,input);
- str[len] = '\0';
- return str;
- }
- int main()
- {
- char input[MAX_SIZE];
- char *result;
- int n;
- printf("请输入任意字符串:");
- scanf("%s",input);
- getchar();
- printf("请输入循环右移位数:");
- scanf("%d",&n);
- result = move(input,n);
- printf("最终字符串:%s\n",result);
- return 0;
- }