repo.or.cz
/
KandRexercises.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
worked on 1-12
[KandRexercises.git]
/
oneword.c
blob
9da83f97987d2cd7846957a619028d7d89b3b25c
1
#include <stdio.h>
2
/* exercise 1-12: print the first word on each line */
3
4
main
() {
5
int
c
;
6
int
oword
=
0
;
7
8
while
((
c
=
getchar
()) !=
EOF
) {
9
10
/* if(c == ' ' && oword == 0) { */
11
if
(
c
==
' '
) {
12
oword
=
1
;
13
14
}
else
{
15
if
(
oword
==
0
) {
16
putchar
(
c
);
17
}
18
19
if
(
c
=
'
\n
'
) {
20
oword
=
0
;
21
putchar
(
'
\n
'
);
22
}
23
24
}
25
26
}
27
putchar
(
'
\n
'
);
28
}