Prints input one word per line. - C Data Type

C examples for Data Type:char

Description

Prints input one word per line.

Demo Code

#include <stdio.h>

int main(void){
    int c = 0, linestarted = 0;
    /*from  w w  w  .  j  a  v a  2  s .  c o  m*/
    printf("Input some characters, then press Ctrl+D.\n");
    
    while ((c = getchar()) != EOF)
        if (c == ' ' || c == '\t' || c == '\n') {
            if (!linestarted) {
                putchar('\n');
                linestarted = 1;
            }
        } else {
            putchar(c);
            linestarted = 0;
        }

    return 0;
}

Result


Related Tutorials