finished 1-13
[KandRexercises.git] / oneword.c
blobf2c47428427a239e2f092d2d98e891b556d4e8e2
1 #include <stdio.h>
2 /* exercise 1-12: print the first word on each line */
3 /* general idea:
4 accept input line
5 print up to first word, once a space is read stop for that line
6 begin reading again on next line
7 stop once EOF is read
8 possibly putchar after all input is read
9 */
10 main() {
11 int c;
12 int oword = 0;
14 while((c = getchar()) != EOF) {
16 /* if(c == ' ' && oword == 0) { */
17 if(c == ' ') {
18 oword = 1;
20 } else {
21 if(oword == 0) {
22 putchar(c);
23 } else if(c == '\n') {
24 oword = 0;
25 putchar('\n');
31 putchar('\n');