本题要求编写函数,将输入字符串的前3个字符移到最后。
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main(){
char s[100];
scanf("%s", s); //s="abcdefg\0"
char b[100];
strcpy(b, s+3); //b="defg\0"
s[3] = '\0'; //s="abc\0"
strcat(b,s); //s="defgabc\0"
printf("%s\n", b);
return 0;
}
运行截图: