#include<stdio.h>
#include<assert.h>
#include<string.h>
void reverse(char* left, char* right)
{
assert(left);
assert(right);
while (left < right)
{
char tmp = *left;
*left = *right;
*right = tmp;
left++;
right--;
}
}
left_move(char* arr,int k)
{
assert(arr);
int len = strlen(arr);
assert(k<len);
reverse(arr,arr+k-1);
reverse(arr+k,arr+len-1);
reverse(arr,arr+len-1);
}
int main()
{
char arr[] ="abcdef";
left_move(arr,14);
printf("%s\n",arr);
}
#include<stdio.h>
#include<assert.h>
#include<string.h>
void left_move(char* arr,int k)
{
assert(arr);
int right = strlen(arr);
for (int i = 0; i < k; i++)
{
char tmp = *arr;
for (int j = 0; j < right; j++)
{
*(arr + j) = *(arr + j+1);
}
*(arr + right - 1) = tmp;
}
}
int main()
{
char arr[] ="abcdef";
left_move(arr,2);
printf("%s\n",arr);
}