Skip to content

Commit

Permalink
Create wc.c
Browse files Browse the repository at this point in the history
  • Loading branch information
chadbrewbaker authored Sep 19, 2024
1 parent afbc29d commit 9499809
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions wc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>

int main() {
int c;
long lines = 0, words = 0, chars = 0;
bool in_word = false;

while ((c = getchar()) != EOF) {
chars++;

if (c == '\n') {
lines++;
}

if (isspace(c)) {
in_word = false;
} else if (!in_word) {
in_word = true;
words++;
}
}

printf("%ld %ld %ld\n", lines, words, chars);

return 0;
}

0 comments on commit 9499809

Please sign in to comment.