Bell 32V development
[unix-history] / usr / lib / learn / C / L14.2b
#print
Write a program which counts the number of five letter
words in its input (define a word as anything between
blanks, tabs or newlines). Compile and run it, then type "ready".
Note that all that is wanted is the total number of
five letter words - nothing was said about distinct
words. Just count the number of times exactly five
characters appear between spaces.
#once #create Ref
This is a passage of text which contains
exactly twelve words of five letters.
Words may appear at the start or at the final
part of a line. Other words show up in
the middle. Avoid counting seven or eight letters
but every five must be noted.
#user
a.out <Ref >xxx
grep 12 xxx >/dev/null
#succeed
/* one way to count five letter words */
\b#include <stdio.h>
main()
{
int since, wdnum, c;
since = 0;
while ((c=getchar()) != EOF) {
if (c == ' ' || c == '\t' || c == '\n') {
if (since == 5)
wdnum++;
since = 0;
}
else
since++;
}
printf("%d\n", wdnum);
}
#log
#next
15.1a 10