/* Find all lines longer than a certain length, 80 by default 
   usage: getlonglines filename <length> 
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
	int length, lmax = 80;
	char buf[1024];
	FILE *fp;
	if (argc < 2) {
		fprintf(stderr, "Usage %s filename <length.\n", argv[0]);
		exit(-1);
	}

	if (!(fp = fopen(argv[1], "r"))) {
		fprintf(stderr, "couldn't open %s\n", argv[1]);
		exit(-1);
	}

	if (argc > 2)
		lmax = atoi(argv[2]);

	while (fgets(buf, 1024, fp)) {
		length = strlen(buf);
		if (length > lmax)
			printf("%s: %d : %s", argv[1], length, buf);
	}
	fclose(fp);
	exit(0);
}
