blob: a9301601b4b34bfbde39c2501308e3f205796b0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
/*
Exercise 1-9. Write a program to copy its input to its output, replacing each
string of one or more blanks by a single blank.
===
*/
#include <stdio.h>
int main () {
int c, w;
w=0; /* word: 0=space, 1=word */
while ((c=getchar())!=EOF) {
if (c!=' ' && !w) w=1; /* word begins */
if (w) putchar(c); /* print character */
if (c==' ' && w) w=0; /* word ends */
}
}
|