

#include <stdio.h>

/* This program takes a file and forces newlines at blanks that occur
after 70 characters
or after sentence endings. 
*/

main(argc, argv)
int argc;
char *argv[];
{
	int c, prevchar, charactercount, linecount;
	if (argc < 2) {linecount = 55;} else {linecount = atoi(argv[1]);}
	charactercount = 0; /* counts characters on a new line */
	prevchar = 0; /* looking for sentence ends */
	while ((c = getchar()) != EOF)
	{
		if (c == '\n') {
			putchar('\n');
			charactercount = 0;
		} else if ((c == ' ') && (charactercount >= linecount)) {
			putchar('\n');
			charactercount = 0;
		} else if ((c == ' ') && (prevchar == '.')) {
			putchar('\n');
			charactercount = 0;
		} else {
			putchar(c);
			charactercount++;
		}
		prevchar = c;
	}
}
