How to input a sentence and print every word in a seperate line in C

1 Answer

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

int main(void)
{
    char s[30];
    int i;
    
    printf("Enter a sentence: ");
    gets(s);
    
    for (i = 0; i < strlen(s); i++)
    {
        if (s[i] != ' ')
            printf("%c", s[i]);
        else
            printf("\n");
    }
            
    return 0;
}


/* 
run:

Enter a sentence: I Love To Code In C
I
Love
To
Code
In
C

*/




answered Sep 14, 2014 by avibootz

Related questions

...