aboutsummaryrefslogtreecommitdiff
path: root/1/12.c
blob: 5803164820c520871bed2cf5349e91bb48827035 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
	Exercise 1-12. Write a program that prints its input one word per line.
	===
*/

#include <stdio.h>

int main () {
	int c, w;

	w=0;	/* word: 0=space, 1=word */
	while ((c=getchar())!=EOF) {
		if (c==' ' || c=='\t' || c=='\n')
			w=0;			/* end word */
		else if (!w) {		/* start word */
			w=1;			
			putchar('\n');
		}
		if (w) putchar(c);	/* print word */				
	}
	putchar('\n');
}