print each word of the sentence in a new line In C

print each word of the sentence in a new line In C

 

Code: 


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
   char s[1001];
    scanf("%[^\n]", s);
    int i=0;
    while (s[i]!='\0') {
    if (s[i]== ' ') {
    printf("\n");
    } else printf("%c",s[i]);
    i++;
    }
   
    return 0;
}




No comments: