C Language --> left-hand string
Problem description: assume there is a string: ABCDE, which is a left-handed character to get the new string BCDEA, and the left-handed two characters to get the new string CDEAB code implementation:
# Include <stdio. h> # include <string. h> void reverse (char * left, char * right) {while (left <right) {char tmp = * left; * left = * right; * right = tmp; left ++; right -- ;}} void left_move (char * str, int k, int len) {reverse (str, str + k-1); reverse (str + k, str + len-1); reverse (str, str + len-1);} int main () {char str [] = "ABCDE";/* original string: ABCDE */int k = 0; int len = strlen (str); printf ("Please input several characters for rotation:"); scanf ("% d", & k ); while (k> len) {printf ("the number is too large. Enter"); scanf ("% d", & k) ;} left_move (str, k, len); printf ("% s \ n", str); return 0 ;}
Result: