#include <stdio.h>
#define MAXLINE 81

/***********************************************************************

			interleave

************************************************************************

Program accepts two or more files and interleaves the lines from
the files and inserts blank lines

Programmer: D.G.Messerschmitt
Date: Jan. 7, 1983
*/

main(argc,argv)
int argc;
char *argv[];

{
	int no_files,i;
	char line[MAXLINE];

	FILE *fopen();
	FILE *file[10];

	no_files = argc-1;

/* open all the input files */

	for(i=0; i<no_files; ++i)

		if((file[i] = fopen(argv[i+1],"r")) == NULL) {
			fprintf(stderr,"File %s could not be opened\n",
				argv[i+1]);
			exit(1);
			}

/* read one line from each file in turn, writing to standard output */

	for(;;)	{

		for(i=0; i<no_files; ++i)	{

			if(fgets(line,MAXLINE,file[i]) == NULL)
				exit(0); /* EOF encountered */

			fputs(line,stdout);
			}

		/* put out a blank line */

			printf("\n");
		}
}
