#include<stdio.h>
#include<string.h>
void connect(char *st1, char *st2, char *q)
{
for(;*st1!='\0';)
{
*q=*st1;
st1++;
q++;
}
for(;*st2!='\0';)
{
*q=*st2;
st2++;
q++;
}
*q='\0';
}
int main()
{
char soul[20];
printf("请输入字符串: \n");
gets(soul);
int len,m;
printf("请输入想要交换的位置m,(注意m须小于总字符串长度): \n");
scanf("%d",&m);
len = strlen(soul);
char *goal1 = new char[m+1];
char *goal2 = new char[len-m+1];
memcpy(goal2,&soul[m],len-m);
memcpy(goal1,&soul[0],m);
char c[30];
char *p;
p=c;
connect(goal2,goal1, p);
printf("%s\n",c);
delete []goal1;
delete []goal2;
delete []p;
return 0;
}
c language input string, enter an integer m, m positions from before and after the exchange of the two, using the pointer
Guess you like
Origin blog.csdn.net/little_tiger_/article/details/104236773
Recommended
Ranking