blob: a95754280ddeb761eb4eaf92dad0c411e32161d9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include "gbos.h"
/* wc: count lines, words, chars of stdin (like `wc`). */
void main(void) {
unsigned int lines = 0, words = 0, chars = 0;
unsigned char inword = 0;
char c;
for (;;) {
c = readc();
if (c == EOF) break;
chars++;
if (c == '\n') lines++;
if (c == ' ' || c == '\n' || c == '\r' || c == '\t') {
inword = 0;
} else if (!inword) {
inword = 1;
words++;
}
}
putu(lines); putc(' '); putu(words); putc(' '); putu(chars); nl();
}
|