关于语句倒置 部分理解 c语言实现的

 #include <stdio.h>
#include <string.h>
void output(char *str)
{
  char* tail = strchr(str,' ');

  if (tail == NULL)
    printf("%s",str);
  else
    {

      output(tail + 1);

      *tail = '\0';
      printf(" %s",str);
    }
}
int main()
{
  char str[81];
  gets(str);
  output(str);
  putchar('\n');
  return 0;
}

output(tail + 1);

  *tail = '\0';
  printf(" %s",str);这一段一直没有理解 能否讲解一下

感觉这是个递归,检测到空格就会向后移继续检测,直到检测完最后一个单词,打印出来才会回到上一级,也就是倒数第二个单词,以此类推,也就把所有的单词都倒过来打印了

*tail = '\0';就是使str这个字符串加上结尾标志,不然输出的话会有乱码,第二句就是把字符串str的内容输出

c中字符串末尾都要是\0结束.
执行到最后,tail已经 是最后一个指针的位置了,需要把他置成0,这样再下面输出的时候,就知道到那个字节结束了

因为are和how之间是空格而不是字符结束符,不加字符结束符的话printf无法输出字符串