/* print a set of files, starting each new one on a new page, with a * running title and page number. */ #include #define PAGE 25 /* number of lines per page */ #define MAXLINE 1000 void page(FILE *fp, char *name) { char line[MAXLINE]; int lc, pc; lc = 0; pc = 1; while ((fgets(line, MAXLINE, fp)) != NULL) { if (lc == 0) { printf("\n--%s: page %d--\n\n", name, pc); pc++; } printf("%s", line); lc = (lc + 1) % PAGE; } } int main(int argc, char *argv[]) { FILE *fp; int i; if (argc == 1) { fprintf(stderr, "error: specify at least one input file\n"); exit(1); } for (i = 1; i < argc; i++) { if ((fp = fopen(argv[i], "r")) == NULL) { fprintf(stderr, "error: unable to open file: %s\n", argv[i]); exit (2); } page(fp, argv[i]); } return 0; }