/*
 * K&R C Programming Language
 * -------------------------------------------------------------
 * Excersise 1-18
 *
 * Write a program to remove trailing blanks and tabs from each
 * line of input, and to delete entirely blank lines.
 *
 */

#include <stdio.h>

int
main(int argc, char *argv[])
{
    int i, c;
    char buf[BUFSIZ];
    int empty;

    i = 0;
    empty = 1;
    while ((c = getchar()) != EOF) {
        if (c != ' ' && c != '\t' && c != '\n') {
            if (i)
                printf("%s", buf);
            putchar(c);
            i = 0;
            empty = 0;              /* current line is not empty */
        } else if (c == '\n') {
            if (!empty)             /* if current line is not empty */
                putchar(c);
            i = 0;
            empty = 1;
        } else {
            buf[i++] = c;
            buf[i] = '\0';
        }
    }

    if (i && c != EOF)
        printf("%s", buf);
    return 0;
}
