dos_compilers/Microsoft C v203/CAT.C
2024-06-30 13:40:22 -07:00

33 lines
640 B
C
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* (This program is from p. 154 of the Kernighan and Ritchie text */
#include <stdio.h>
main(argc, argv) /* cat: concatenate files */
int argc;
char *argv[];
{
FILE *fp, *fopen();
if (argc == 1) /* no args; copy standard input */
filecopy(stdin);
else
while (--argc > 0)
if ((fp = fopen(*++argv, "r")) == NULL) {
fprintf(stderr,
"cat: can't open %s\n", *argv);
exit(1);
} else {
filecopy(fp);
fclose(fp);
}
exit(0);
}
filecopy(fp) /* copy file fp to standard output */
FILE *fp;
{
int c;
while ((c = getc(fp)) != EOF)
putc(c, stdout);
}
p) /* cop