modified lenhist
[KandRexercises.git] / 1-12.c
blob678998d0141cc9f9a0f344476c3e5b73794d1941
1 #include <stdio.h>
2 /* exercise 1-12: print input, one word per line */
3 /* general idea:
4 accept input line
5 print newline if whitespace is encountered
6 continue reading input, but don't copy to stdout
7 begin copying again on next line after reading non-whitespace chars
8 stop once EOF is read
9 */
10 main() {
11 int c;
13 while((c = getchar()) != EOF) {
15 if(c == ' ' || c == '\t' || c == '\n') {
16 putchar('\n');
17 while(c == ' ' || c == '\t' || c == '\n')
18 c = getchar();
20 putchar(c);
23 putchar('\n');