/* * File: kat.c * Usage: kat * ---------------- * This program prints files to standard output. * Each of the program arguments is assumed to be a filename, which is then * printed to stdout. */ #include #include #include "genlib.h" int main(int argc, string argv[]) { FILE *sourceFile; int ch; /* for reading characters, use int to detect EOF */ int i; /* loop var */ /* note: argv[0] is the name used to run this, so argc is always >= 1 */ if (argc < 2) { printf("Missing argument(s).\n"); printf("\tUsage: %s \n",argv[0]); exit(1); } /* for each file */ for ( i = 1; i < argc; i++) { sourceFile = fopen(argv[i], "r"); if (sourceFile == NULL) { /* indicates error trying to open file */ printf("%s: unable to open file.\n",argv[i]); } else { /* sourceFile != NULL, so file successfuly opened */ printf("\n<==:%s:==>\n",argv[i]); while ((ch = getc(sourceFile)) != EOF) { putc(ch, stdout); } /* end while */ fclose(sourceFile); } /* end else */ } /* end for i */ return(0); /* no errors */ } /* end main() */