/*
 * Problem 1-18
 * Write a program to remove trailing blanks and tabs from each 
 * line of input, and to delete entirely blank lines.
 * Copyright (c) 1998 by John Weber.  All rights reserved.
 */
#include <stdio.h>
#define MAXLEN 1000

int main(void)
{
	int count;
	char line[MAXLEN];	/* current input */
	int len;		/* length of current input */

	count = 0;
	while( (len = linelength(line,MAXLEN)) != EOF ) {
		printf("Line %d: %d\n",++count,len);
		if( len > 80 ) 
			printf("%s",line);
	}
}

int linelength(char line[], int maxlen)
{
	int c, len = 0, counter = 0;

	while( (c = getchar()) != EOF && c != '\n' && counter < maxlen ) { 
		line[counter++] = c;
	}
        if( c == EOF ) return EOF;
	if( counter == maxlen && c != '\n') {	/* Line larger than max number of characters */
		len += counter;
		counter = linelength(line,maxlen);
	}

	len += counter;
	line[counter++] = '\0';

	return len;
}
