Given a sentence, , print each word of the sentence in a new line.

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

int main() {

    char *s,tmp;
    int len,i;
    s = malloc(1024 * sizeof(char));
    scanf("%[^\n]", s);
    s = realloc(s, strlen(s) + 1);
    //Write your logic to print the tokens of the sentence here.
   
    len=strlen(s);
    for(i=0;i<len;i++){
        tmp=s[i];
        if(tmp==' '){
    printf("\n");
            continue;
}
        printf("%c",s[i]);
       
    }
    return 0;
}

Comments

Popular posts from this blog

aaabb to32 ,aabbb to a2b3 convert in c-asr

a2b3 output aabbb c program and beautiful use of getchar() ,isdigit() ,atoi() functions and stdlib.h header file-asr

C program to print square spiral number pattern - asr