int main(int argc, char const *argv[])
{
char a[32] = "i love China";
char t;
char *p = a;
char *q = a + strlen(a) - 1;
char *m = NULL;
//整体倒过来
while (p < q)
{
t = *p;
*p = *q;
*q = t;
p++;
q--;
}
printf("%s\n", a);
//把每个单词倒过来
p = q = a;
while (*p != '\0')
{
while (*p ==' ')
p++;
q = p; //找单词结尾
while (*q != ' ' && *q != '\0')
q++;
m = q; //暂存空格和\0地址
q--;
while (p < q)
{
t = *p;
*p = *q;
*q = t;
p++;
q--;
}
p = m;
}
printf("%s\n", a);
return 0;
}
03-27
4375
08-11
495
09-12