This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
sys_prog/HW1-wordcount/wordcount.c

23 lines
415 B
C
Raw Normal View History

2019-09-18 08:48:07 +00:00
// vim: set ts=4 sw=4 et tw=80:
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
int main() {
int c;
bool in_space = true;
unsigned int w = 0;
while ((c = getchar()) != EOF) {
if (isspace(c)) {
if (!in_space) {
w++;
in_space = true;
}
} else {
in_space = false;
}
}
printf("%u\n", w);
}