C语言中如何改变字符串中单词位置?

C语言中如何将输入的字符串here is the world,输出为world the is here

#include <stdio.h>
#include <string.h>
int main()
{
    char buf[100] ={0};
    int i;
    gets(buf); //输入一行数据
    int len = strlen(buf) -1;
    while(1)
    {
        if(len < 0)
            break;
        else if(len == 0)
        {
            printf("%s",&buf[0]);
            break;
        }
        else 
        {
            if(buf[len] == ' ')
            {
                printf("%s ",&buf[len+1]);
                buf[len] = 0;
            }
            
        }
        len--;
    }
    return 0;
}