#include<stdio.h>
#include<string.h>
void Rotate(char *start,char *end)
{
if(start == NULL || end == NULL) return ;
while(start<end)
{
char temp = *start;
*start = *end;
*end = temp;
--end;++start;
}
}
void RotateString(char *a,int n)
{
int i,j;
char *start =a;
char *end = a;
while(*start != '\0')
{
if(*start == ' ')
{
++start;++end;
continue;
}
else if(*end == ' ' || *end == '\0')
{
Rotate(start,--end);
start = ++end;
}
else
++end;
}
start = a;
Rotate(start,end-1);
printf("%s\n",a);
}
int main()
{
char a[] ="how are you";
printf("source string: %s\n",a);
RotateString(a,11);
return 0;
}
运行结果:
source string: how are you
you are how
C语言实现字符串中的单词的逆转
最新推荐文章于 2022-12-05 20:16:17 发布