Done wordcount for me

This commit is contained in:
Claudio Maggioni 2019-09-18 10:48:07 +02:00
parent 6a265e23b7
commit c072df226b

22
HW1-wordcount/wordcount.c Normal file
View file

@ -0,0 +1,22 @@
// 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);
}