-
Notifications
You must be signed in to change notification settings - Fork 4
/
exercise1-12.c
47 lines (40 loc) · 937 Bytes
/
exercise1-12.c
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
40
41
42
43
44
45
46
47
#include <stdio.h>
#define IN 1 // inside a word
#define OUT 0 // outside a word
int main(void)
{
int c, state;
state = OUT;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '\n' || c == '\t') {
if (state == IN) {
printf("\n");
state = OUT;
}
}
else {
putchar(c);
if (state == OUT)
state = IN;
}
}
return 0;
}
/*
int main(void)
{
int current, previous; // current = current character, previous = previous character
previous = ' ';
while ((current = getchar()) != EOF) {
if (current == ' ' || current == '\n' || current == '\t') {
if (previous != ' ' && previous != '\n' && previous != '\t') {
printf("\n");
}
}
else
putchar(current);
previous = current;
}
return 0;
}
*/