实现字符串逆置
例如:char a[]=”hello my student”
输出:student my hello
#include<stdio.h>
#include<string.h>
int main(int argc, const char *argv[])
{
char a[]="hello my student";
char b[20]="";
int i,j=0,k=0,t,m;
for(i=strlen(a)-1;i>=0;i--)
{
b[k++]=a[i];
}
printf("%s\n",b);
i=0;
while(b[i]!='\0')
{
while(b[j]!=' '&&b[j]!='\0')
{
j++;
}
t=j-1;
while(i<t)
{
m=b[i];
b[i]=b[t];
b[t]=m;
i++;
t--;
}
while(b[j]==' ')
j++;
i=j;
}
puts(b);
return 0;
}
【输出样例】
tneduts ym olleh
student my hello