summaryrefslogblamecommitdiff
path: root/ch1/whitespace_counter.c
blob: ea441e2c983c38e9aa834236cb51b9f937811b3c (plain) (tree)





















                                    
#include<stdio.h>

/*
 * Count whitespace in input
 */
main() {
    int c, n_whitespace;

    n_whitespace = 0;

    while ((c = getchar()) != EOF) {
        if (c == '\n')
            ++n_whitespace;
        if (c == '\t')
            ++n_whitespace;
        if (c == ' ')
            ++n_whitespace;
    }


    printf("%d\n", n_whitespace);
}