颠倒文本,

颠倒文本,求助。Sample Inputolleh !dlrowmI morf .udhI ekil .mcaSample Outputhello world!Im from hdu

颠倒文本,求助。
Sample Input 


olleh !dlrow
m'I morf .udh
I ekil .mca


Sample Output 


hello world!
I'm from hdu.
I like acm.

这我写的代码,不知为何在OJ系统上AC不了。还有没有更好的写法?

#include <stdio.h>
int main ()
{
char a[101];
int i=0,j=0;
gets(a);

while (a[i]!='\0')
{
if (a[i]==' ')
{ j=i-1;
while (a[j]!=' ')
{printf ("%c",a[j]);
if (j==0)
break;
j--;
}
printf (" ");
}
i++;
}
i=i-1;
while (a[i]!=' ')
{
printf ("%c",a[i]);
i--;
}
printf ("\n");
return 0;
}


[解决办法]

探讨

C/C++ code

#include <string.h>
#include <stdio.h>

char* strrev(char *str)
{
size_t len = strlen(str);
char* start = str;
char* end = str + len - 1;
char ch;

if(str != NULL)
……