字符串移位问题
要求把字符串元素进行向位移,比如:char s[ ] = "abcdef";
cyclicRightShift( s, 1 );//向右位移1位
printf("%s\n", s );
cyclicRightShift( s, 2 );
printf("%s\n", s );
cyclicRightShift( s, 3 );
printf("%s\n", s );
则输出:
fabcde
defabc
abcdef
下面是小弟的初步构思:
#include<stdio.h>
main()
{
char s[ ] = "abcdef";
cyclicRightShift( s, 1 );
printf("%s\n", s );
cyclicRightShift( s, 2 );
printf("%s\n", s );
cyclicRightShift( s, 3 );
printf("%s\n", s );
}
void cyclicRightShift ( char s[ ], int n )
{
int length, x;
x=n;
length=strlen(s);
for (x=0; x<length; x++)
{
}
}//循环里就不知道怎么写了,哪位高手指点一下,谢谢。