已处理最后字串的完整代码
#include <stdio.h>
void main()
{
char str[]="you are a student";
printf(str);
printf("\n");
char *p,*q;
char temp;
p=q=str;
while(*q!='\0')
{
q++;
}
q--;
while(p<=q)
{
temp=*p;
*p=*q;
*q=temp;
p++;
q--;
}//反转整个字符串
printf(str);
printf("\n");
char *s;
q=p=s=str;//指针指向开始位置
while(*q!='\0')
{
if(*q==' '||*(q+1)=='\0')
{
p--;
if(*(q+1)=='\0')//处理最后一个字串
p++;
while(s<=p)
{
temp=*p;
*p=*s;
*s=temp;
s++;
p--;
}//反转局部字符串
s=q+1;
p=q;
}
q++;
p++;
}
printf(str);
printf("\n");
}