K&R WC统计行数、单词数、字符数

近来无事,随手翻翻书吧。。。。。

#include<stdio.h>

#define OUT  1
#define IN   0

main()
{
    int c, nl, nc, nw, state;

    nl = nc = nw = 0;
    state = OUT;
    while ((c = getchar()) != EOF) {
        nc ++;

        if (c == '\n') {
            nl ++;
        }
        if (c == ' ' || c == '\t' || c == '\n') {
            state = OUT;
        } else if (state == OUT) {
            state = IN;
            nw ++;
        }
    }

    printf("%d\t%d\t%d\n", nl, nw, nc);
}

wc的

原文地址:https://www.cnblogs.com/cloudstorage/p/2743820.html