Input Format
The first and only line contains a sentence, .
Constraints
Output Format
Print each word of the sentence in a new line.

hackerrank printing tokens problem solution in c programming

Printing Tokens problem solution in C programming | HackerRank

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

int main()
{
    char *s;
    s = malloc(1024 * sizeof(char));
    scanf("%[^\n]", s);
    s = realloc(s, strlen(s) + 1);
    int len = strlen(s);
    for(int i = 0; i < len; i++) {
        if(s[i] == ' ') {
            printf("\n");
        }
        else {
            printf("%c", s[i]);
        }
    }
    free(s);
    return 0;
}