#include //from K&R C // // ... as adapted by Jim M into a style he likes better. #define INSIDE_WORD 1 #define OUTSIDE_WORD 0 /* count lines, words, and characters in input */ int main(){ int character, n_lines, n_words, n_chars, state; state = OUTSIDE_WORD; n_lines = n_words = n_chars = 0; while ((character = getchar()) != EOF) { n_chars++; if (character == '\n'){ n_lines++; } if (character == ' ' || character == '\n' || character == '\t'){ state = OUTSIDE_WORD; } else if (state == OUTSIDE_WORD) { state = INSIDE_WORD; n_words++; } } printf(" lines=%d words=%d chars=%d \n", n_lines, n_words, n_chars); return 0; }