Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/cprogs/Ex_1.12_word_per_line.c
1240 views
1
/**
2
*
3
* Exercise 1.11 - Write a program that prints its input one word per line.
4
*
5
* */
6
7
#include <stdio.h>
8
#define IN 1
9
#define OUT 0
10
11
/* This program counts the number of lines, characters and words */
12
int main (int argc, char *argv[]) {
13
int c,state;
14
state = IN;
15
while((c=getchar()) != EOF) {
16
if(c==' ' || c == '\t')
17
state=OUT;
18
else if (state == OUT) {
19
state=IN;
20
putchar('\n');
21
putchar(c);
22
23
}
24
else
25
putchar(c);
26
}
27
}
28