# include <stdio.h> # include <stdlib.h> # include <string.h> # define MAX 20 void Contra_solem(char *str, int move) { char *pstart = NULL; char *pend = NULL; char *src = NULL; int i = 0; pstart = str; pend = (str + strlen(str)); src = str; for (i = 0; i < move; i++) { *pend++ = *pstart++; } while (pstart <= pend) { *src = *pstart; pstart++; src++; } } int main() { char str[MAX] = "abcdefgh"; int move = 0; printf("源字符串為:%s\n",str); printf("輸入想要左旋字符的個數:"); scanf("%d", &move); while (move > strlen(str)) { printf("@@@輸入太大,請重新輸入!@@@\n"); scanf("%d",&move); } Contra_solem(str,move); printf("左旋%d個字符後的字符串為:%s\n",move,str); system("pause"); return 0; }