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

#define SIZE 300

int main(void)
{
    char sentence[SIZE];
    char *words[100];

    int count = 0;

    printf("Enter a line of text:\n");
    fgets(sentence, SIZE, stdin);

    sentence[strcspn(sentence, "\n")] = '\0';

    char *tokenPtr = strtok(sentence, " ");

    while (tokenPtr != NULL)
    {
        words[count] = tokenPtr;
        ++count;

        tokenPtr = strtok(NULL, " ");
    }

    printf("\nThe sentence with words reversed is:\n");

    for (int i = count - 1; i >= 0; --i)
    {
        printf("%s", words[i]);

        if (i != 0)
        {
            printf(" ");
        }
    }

    puts("");

    return 0;
}