
/* This program breaks up a file into a set of pieces
pieces where each piece is NUMLINES long and creates
Assumes the input is from standard input.
Creates files temp.1, temp.2, ...

If you send this through mail, remember to remove trailing
newlines when you cat the files together (if this is an
executable).
*/

#define NUMLINES 15500


#include <stdio.h>
#include <ctype.h>
main()
{
	printf("A reminder: if you send a uuencoded file through\n");
	printf("the mail, remember to remove the newline that mail\n");
	printf("adds to the bottom of each file.\n");
	int c,atflag;
	FILE *fopen(); 
	FILE *fp;
	char filestring[20];
	int fsindex = 0;
	int lines=0;  /* have not yet started to read */
        int extension = 1;
	strcpy(filestring, "temp.1");
	if ((fp = fopen(filestring, "w")) == NULL) {
				printf("Can't open %s\n", filestring);
        }
	c = getchar();
	while(c !=EOF){
		putc(c, fp); /* no matter what, put it out */
		if (c == '\n') { 
		   lines++;
		   if (lines == NUMLINES) {
			fclose(fp); /* done with this file*/
		        extension++; /* next file */
			if (extension < 10) {
		           filestring[5] = (char) ('0' + extension);
			   filestring[6] = 0;
			} else {
			   filestring[5] = (char) ('0' + (int) extension/10);
			   filestring[6] = (char) ('0' + extension%10);
			   filestring[7] = 0;
		        }
	                if ((fp = fopen(filestring, "w")) == NULL) {
				printf("Can't open %s\n", filestring);
        	        }
			lines = 0;
		   }
		} 
	        c = getchar();
	}
}	
