Give a Sentences and print each words of the sentences in a new line.

 


Input-  

This is blogging site


In the given string, there are four words ["This", "is", "blogging", "site"]. 

We have to print each of these words in a new line.


Output - 

This

is

blogging

site


Constraints : 1<=len(s)<=1000


Code in C:

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

int main() {

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


Comments