标签:
????#include <stdio.h>
int main()
{
char str[]="student a am i";
printf("%s\n",str);
char *p,*q;
char temp;
p=q=str;
while(*q!='\0')
{
q++;
}
q--;
while(p<=q)
{
temp=*p;
*p=*q;
*q=temp;
p++;
q--;
} //反转整个字符串
char *s;
q=p=s=str; //指针指向开始位置
while(*q!='\0')
{
if(*q==' '||*(q+1)=='\0')
{
if(*q==' ') //处理空格
p--;
while(s<=p) //反转局部字符串
{
temp=*p;
*p=*s;
*s=temp;
s++;
p--;
}
s=q+1;
p=q;
}
q++;
p++;
}
printf(str);
printf("\n");
return 0;
}
标签:
原文地址:http://blog.csdn.net/yangshuangtao/article/details/44925945