summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/L13.1a
blob: a70bd13fda7c51b754928984e13c6ad647ed2c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#print
Write a program which reads
its input and counts the number of
characters and the number of spaces
(where a space is either a blank or
a tab or a newline).  Print both numbers.
Compile, test, and type "ready".
#once #create Ref
hoboken harrison newark roseville avenue grove street
east orange brick church orange highland avenue
mountain station south orange maplewood millburn short hills
summit chatham madison convent station morristown
new providence	murray hill berkeley heights
gillette stirling millington lyons basking ridge
bernardsville far hills peapack gladstone
#user
a.out <Ref >x1
a.out <Ref >x2
grep 348 x1 >/dev/null && grep 45 x2 >/dev/null
#succeed
 #include <stdio.h>
/* One way: */

main() {
	int nchar, nspace;
	char c;

	nchar = nspace = 0;
	while ((c = getchar()) != EOF) {
		nchar++;
		if (c == ' ' || c == '\t' || c == '\n')
			nspace++;
	}
	printf("spaces = %d, chars = %d\n", nspace, nchar);
}
#log
#next
14.1a 10
14.2a 5