#include "common.h"
#include <ctype.h>

#define BUF_LEN 80

int main(int ac, char *av[])
{
    char word[BUF_LEN];
    int in_word = 0, word_length = 0, column_number = 0, c;

    while (EOF != (c = getchar())) {
        if (c == ' ' || c == '\n') {
            if (in_word) {
                in_word = 0;
                word[word_length] = '\0';
                if (column_number + word_length >= BUF_LEN) {
                    putchar('\n');
                    column_number = 0;
                }
                if (column_number == 0) {
                    printf("%s", word);
                    column_number += word_length;
                }
                else {
                    printf(" %s", word);
                    column_number += word_length + 1;
                }
                word_length = 0;
            }
        }
        else if (isalpha(c)) {
            in_word = 1;
            word[word_length++] = c;
        }
        else
            fprintf(stderr, "Skipping unexpected character %c\n", c);
    }
    /* Take care of the last word, in case it has not been printed */
    if (in_word && word_length > 0) {
        word[word_length] = '\0';
        if (column_number + word_length >= BUF_LEN)
            putchar('\n');
        printf("%s%s", (column_number == 0) ? "" : " ", word);
    }
    putchar('\n');

    return 0;
}
