#include<stdio.h>
int main()
{
void Left_spin(char arr[], int k);
char str[10] = "AABCD";
int x = 0;
printf("请输入要左旋的个数<1--5>:\n");
scanf("%d", &x);
Left_spin(str, x);
printf("%s\n", str);
system("pause");
return 0;
}
void Left_spin(char arr[], int k)
{
int my_strlen(const char *str);
int i = 0;
char * Pstart = arr ;
char *Pend = arr + my_strlen(arr) ;
char *Pcur = arr + k;
for (i = 1; i <= k; i++)
{
*Pend = *Pstart ;
Pend++;
Pstart++;
}
while (Pcur <= Pend)
{
*(Pcur - k) = *Pcur;
Pcur++;
}
*(Pend - k + 1) = '\0';
}
int my_strlen(const char *str)
{
int count = 0;
while (*str++)
{
count++;
}
return count;
}
转载于:https://blog.51cto.com/10741764/1709175