blob: e7d4d253d4dcfb0b791fd2d468ffa5b1398ba2d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <stdio.h>
#include <stdbool.h>
/* Copy stdin to stdout, replacing consecutive spaces with a single space
Edge case: a leading space is retained if there are leading spaces.
Edge case: an empty file just doesn't echo anything, but emits a warning on stderr */
int main(void) {
int c = getchar();
if (c == EOF) {
fprintf(stderr, "warning: no input\n");
goto exit;
}
putchar(c);
bool bl = (c == ' ');
while ((c = getchar()) != EOF) {
if ((!bl) || (c != ' ')) {
putchar(c);
}
bl = (c == ' ');
}
exit:
return 0;
}
|