File:  [CSRG BSD Unix] / 43BSDTahoe / usr.lib / learn / C / L14.2b
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:58 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43tahoe
BSD 4.3tahoe

#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 */
 #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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.