Done wordcount for me
This commit is contained in:
parent
6a265e23b7
commit
c072df226b
1 changed files with 22 additions and 0 deletions
22
HW1-wordcount/wordcount.c
Normal file
22
HW1-wordcount/wordcount.c
Normal 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);
|
||||
}
|
Reference in a new issue