实现单词的逆置
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void turn(char *p,char *shou,char *wei)
{
char temp;
while(shou<wei)
{
temp=*shou;
*shou=*wei;
*wei=temp;
shou++;
wei--;
}
}
int main(int argc, const char *argv[])
{
char a[20]="i love china";
int len=strlen(a);
turn(a,a,a+len-1);
int i=0,start=0,end=0;
puts(a);
while(a[i])
{
while(a[i]==' ')
{
i++;
}
start=i;
while(a[i]!=' '&&a[i]!=0)
{
i++;
}
end=i-1;
turn(a,a+start,a+end);
}
puts(a);
return 0;
}