Files
first-repo/word_count.c
2025-02-06 12:54:34 +02:00

25 lines
460 B
C

#include <stdio.h>
#define IN 1
#define OUT 0
int main() {
int character, lines, words, chars, state;
state = OUT;
lines = words = chars = 0;
while ((character = getchar()) != EOF) {
++chars;
if (character == '\n')
++lines;
if (character == ' ' || character == '\n' || character == '\t')
state = OUT;
else if (state == OUT) {
state = IN;
++words;
}
}
printf("\n%d %d %d\n", lines, words, chars);
}