比如说一句话,“I love you!”变成“you! love I”,
char *Reverse(char *s)
{
int n=strlen(s);
char temp[1000];//定义缓冲区的的大小
int q=n-1;
temp[n]='\0'; //最后一个为‘\0’
char *p;
p=s;
int i=0,t=0;
bool flag=true;
while(flag)
{
if (*p==' ')
{
p--;
while(t!=0)
{
temp[q]=*p;
p--;
q--;
t--;
}
temp[q]=' ';
q--;
i+=2;
p+=i;
i=0;
t=0;
}else if (*p=='\0') //如果运行到字符串的末尾
{
p--;
while(t!=0)
{
temp[q]=*p;
p--;
q--;
t--;
}
//break;
flag=false;
}
p++;
i++;
t++;
}
for(i=0;i<n;i++)
{
printf("%c",temp[i]);//重新赋给字符串
}
return s;
}