#include <stdio.h>
#define N 50
void daoxu(char *p) // 整個字符串翻轉
{
char *h = p;
while (*p != '\0')
{
p++;
}
p = p - 1;
char temp;
while(h <= p)
{
temp = *p;
*p = *h;
*h = temp;
p--;
h++;
}
}
void over(char* p) // 以空格爲基準翻轉字符串
{
char *h = p;
char *t = p;
while (*t != '\0')
{
if (*t == ' ')
{
*t = '\0';
daoxu(h);
*t = ' ';
t++;
h = t;
}
else
{
t++;
}
}
}
int main()
{
char str[N] = {0};
printf("請輸入語句:\n");
gets(str);
daoxu(str);
over(str);
puts(str);
return 0;
}