aboutsummaryrefslogtreecommitdiffstats
path: root/rtrailws.c
diff options
context:
space:
mode:
Diffstat (limited to 'rtrailws.c')
-rw-r--r--rtrailws.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/rtrailws.c b/rtrailws.c
new file mode 100644
index 0000000..a1d1956
--- /dev/null
+++ b/rtrailws.c
@@ -0,0 +1,23 @@
+// Remove trailing whitespace.
+#include<stdio.h>
+
+int main (int argc, char *argv[]) {
+ char c;
+ int spacecount = 0;
+ while ( (c = getchar()) != EOF ) {
+ if (c == ' ') {
+ spacecount++;
+ } else if (c == '\n' && spacecount) {
+ putchar('\n');
+ spacecount = 0;
+ } else {
+ if (spacecount) {
+ int i;
+ for (i = 0; i < spacecount; i++)
+ putchar(' ');
+ spacecount = 0;
+ }
+ putchar(c);
+ }
+ }
+}