first commit!
This commit is contained in:
24
word_count.c
Normal file
24
word_count.c
Normal file
@ -0,0 +1,24 @@
|
||||
#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);
|
||||
}
|
Reference in New Issue
Block a user